RE: [Boost-users] Looking for more advanced type_traits-likefunctionality

Agoston Bejo
Hi, 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
::result (true if T::paint() exists) has_member ::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.
Unfortunately that is impossible because templates can only manipulate constants, types and templates, not names. There is a technique that can be used to detect the definition of most operators, but it requires a separate template for each operator and it depends on being able to overload the operators through non-member functions. There may be a way to detect member functions but it cannot be done generically.

Hi,
and what about member typedef's? Is it also that hopeless?
Thx,
Gus
"Ben Hutchings"
Agoston Bejo
: Hi, 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
::result (true if T::paint() exists) has_member ::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.
Unfortunately that is impossible because templates can only manipulate constants, types and templates, not names. There is a technique that can be used to detect the definition of most operators, but it requires a separate template for each operator and it depends on being able to overload the operators through non-member functions. There may be a way to detect member functions but it cannot be done generically.

"Agoston Bejo"
Hi, and what about member typedef's? Is it also that hopeless?
Thx, Gus
See boost/mpl/aux_/has_xxx.hpp -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (3)
-
Agoston Bejo
-
Ben Hutchings
-
David Abrahams