RE: [Boost-users] Looking for more advanced type_traits-likefunctionality
Agoston Bejo <gusz1@freemail.hu>:
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<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.
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" <ben.hutchings@businesswebsoftware.com> wrote in message news:A7F746377BDB7D4EA8E6623AF92F43C8163515@copper.bwsint.com...
Agoston Bejo <gusz1@freemail.hu>:
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<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.
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" <gusz1@freemail.hu> writes:
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