Boost logo

Boost Users :

Subject: Re: [Boost-users] [type traits / MPL] check whether a class has a certain member function
From: Stefan Strasser (strasser_at_[hidden])
Date: 2013-03-07 15:53:30


Am 07.03.2013 20:12, schrieb Jeffrey Lee Hellrung, Jr.:
> The macro you're looking for is BOOST_TTI_HAS_MEMBER_FUNCTION.

> it requires you to know the exact signature of the member
> function. I'm trying to check whether it is ok to call c.f(x), which
> would be satisfied by each of the following 3 signatures (and more):
>
> struct C{
> void f(X);
> void f(X &);
> void f(X const &);
> ...
> };
>
> is there a way to check for that, or do I have to check for all
> (likely) signatures?

> https://groups.google.com/group/comp.lang.c++.moderated/tree/browse_frm/thread/4f7c7a96f9afbe44/c95a7b4c645e449f?pli=1#doc_e5fbc9305539f699
>

Thanks!
it doesn't work for me, because it uses sizeof(void) if the function
call is possible.

However, it is enough to determine whether a member of a given name
exists, without checking the signature. an implementation of has_member
is here: http://www.rsdn.ru/forum/cpp/2720363

Edward, can this be added to TTI, for example as BOOST_TTI_HAS_MEMBER?
not only does this implementation look portable to me, but boost already
uses it internally:
http://www.boost.org/doc/libs/1_47_0/boost/thread/locks.hpp

Stefan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net