C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

function pointer specifiers

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
liftmaster
Guest





PostPosted: Fri Jul 08, 2005 3:00 pm    Post subject: function pointer specifiers Reply with quote



is there a way of specifying a specific overload of some function when
writing function pointer specifier?

I am trying to find information about the return value of of a dereference
operation by interrogating the type of the operator* function pointer. I
can distinguish between member and nonmember operator* and I can specify a
member operator* and test it like this:

template<class It, bool _IsMember_>
struct dereference_properties
{
static yes_t char_test (It::char(*)());
static yes_t char_test (It::char(*)()const);
static yes_t char_test (It::char(*)()volatile);
static yes_t char_test (It::char(*)()const volatile);
// NB no static operator*

static no_t char_test (...);

enum {is_char = sizeof(char_test(&It::operator*))
==sizeof(yes_t) };

};

im sorry for typeos,I don't have a compiler here to check that the code I
am writing is totally correct. obviously the above test is not exaclt the
test I am making.

but fornonmember operator* we cannot do this:

template<class It>
struct dereference_properties<It, false>
{
static yes_t char_test (char(*)(It));
static yes_t char_test (char(*)(It&)const);
static yes_t char_test (char(*)(const It&);

static no_t char_test (...);

enum {is_char = sizeof(char_test(&operator*))
==sizeof(yes_t) };

};

because the compiler has no idea which operator* we want and makes no
attemptto look for operator*s in the namespaceof It.

Is there a way 'round this.

Obviously there is a further limitation that we wish to be able to specify
the overload, but it would be even nicer if, as in the speculative (but
wrong) code above we could specify a few possible overloads and so long as
one and only one of them is fulfilled the compiler would pick the correct
one (as it does for the mnember function operator*).

I hope this is clear. I don't think there is a solution but I don't want
to give up without asking around.

p.s. yes I MUST have the member function pointer, just dereferencing
simply won't do (I think).



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Maxim Yegorushkin
Guest





PostPosted: Sat Jul 09, 2005 2:33 pm    Post subject: Re: function pointer specifiers Reply with quote



On Fri, 08 Jul 2005 19:00:15 +0400, liftmaster <maninalift (AT) another (DOT) com>
wrote:

Quote:
is there a way of specifying a specific overload of some function when
writing function pointer specifier?

Not sure I understand the when part of the sentence.

Quote:
I am trying to find information about the return value of of a
dereference
operation by interrogating the type of the operator* function pointer. I
can distinguish between member and nonmember operator* and I can specify
a member operator* and test it like this:

You can figure out whether an operator exists for a type and then do what
is appropriate for you.
http://groups-beta.google.com/group/comp.lang.c++.moderated/msg/0b8d87e34b64eaf4

--
Maxim Yegorushkin
<firstname.lastname (AT) gmail (DOT) com>

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
liftmaster
Guest





PostPosted: Mon Jul 11, 2005 3:16 pm    Post subject: Re: function pointer specifiers Reply with quote



Finding whether an object defines an operator*, or indeed finding whether
that operator is defined as a member or non-member is not the problem.

The problem is, if the function is a non-member I am unable to specify the
function pointer pointing to that operator*, since I am specifying a
function which is overloaded. If I just write "operator*" the compiler
will not know that I mean

unknow_rtn_t operator*(this_object)

indeed the compiler won't even look for an (as yet) undeclared or
non-local operator*.

As I say I don't think there is a solutin to this problem but if anyone
sees one please let me know.

cheirz


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Maxim Yegorushkin
Guest





PostPosted: Wed Jul 13, 2005 10:44 am    Post subject: Re: function pointer specifiers Reply with quote

On Mon, 11 Jul 2005 19:16:03 +0400, liftmaster <maninalift (AT) another (DOT) com>
wrote:

Quote:
Finding whether an object defines an operator*, or indeed finding whether
that operator is defined as a member or non-member is not the problem.

The problem is, if the function is a non-member I am unable to specify
the
function pointer pointing to that operator*, since I am specifying a
function which is overloaded. If I just write "operator*" the compiler
will not know that I mean

unknow_rtn_t operator*(this_object)

indeed the compiler won't even look for an (as yet) undeclared or
non-local operator*.

As I say I don't think there is a solutin to this problem but if anyone
sees one please let me know.

Sorry, I can not understand what you are trying to do.

If you just need to take an address of operator*, you can use a thunk
function or function object:

template<class R, class A, class B>
R star_operator_thunk(A a, B b)
{
return a * b; // no matter if operator* is a member or a non member
function
}

int main()
{
int(*fn)(int, int) = star_operator_thunk<int, int, int>;
return fn(1, 2);
}

--
Maxim Yegorushkin
<firstname.lastname (AT) gmail (DOT) com>

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.