Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2004-06-07 06:26:53


> I have took a look at some parts of the boost library, but I couldn't find
> what I want, and
>
> that is something like this: How can I determine if a type T has such and
> such member? It
>
> would look like something like this:
>
> has_member<T, paint>::result (true if T::paint() exists)
> has_member<T, m_size>::result (true if T::m_size exists)
>
> The closest to this I could find is boost::type_traits but that does not
> provide this
>
> functionality.

There are two problems:

1) You have to write a separate traits class for every member that you want
to detect, there is no real way to boilerplate this.
2) The techniques used are only supported on a minority of current
compilers.

However, take a look at
http://lists.boost.org/MailArchives/boost/msg52178.php for a working
example.

Also if you want to detect member types (as opposed to member functions)
then there is an almost-boilerplate example in boost/mpl/_aux/has_xxx.hpp.

John.


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