Looking for more advanced type_traits-like functionality
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. Thx, Gus
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)
AFAIK, checking for arbitrary members at compile time is not possible in a portable way. However, it seems that you can check for operators: http://lists.boost.org/MailArchives/boost/msg29007.php Regards, Wolfgang Meyer
"Wolfgang Meyer" <Wolfgang.Meyer@informatik.uni-oldenburg.de> writes:
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)
AFAIK, checking for arbitrary members at compile time is not possible in a portable way.
However, it seems that you can check for operators:
Much better techniques than the ones shown there are now known. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
"David Abrahams" <dave@boost-consulting.com> wrote in message news:ur7srmmpm.fsf@boost-consulting.com...
"Wolfgang Meyer" <Wolfgang.Meyer@informatik.uni-oldenburg.de> writes:
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)
AFAIK, checking for arbitrary members at compile time is not possible in a portable way.
However, it seems that you can check for operators:
Much better techniques than the ones shown there are now known.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
And where are they available, or at least can be read of? Thx, Gus
"Agoston Bejo" <gusz1@freemail.hu> writes:
"David Abrahams" <dave@boost-consulting.com> wrote in message news:ur7srmmpm.fsf@boost-consulting.com...
"Wolfgang Meyer" <Wolfgang.Meyer@informatik.uni-oldenburg.de> writes:
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)
AFAIK, checking for arbitrary members at compile time is not possible in a portable way.
However, it seems that you can check for operators:
Much better techniques than the ones shown there are now known.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
And where are they available, or at least can be read of?
You might look at http://www.boost-consulting.com/boost/boost/detail/is_incrementable.hpp, though it could be improved by using the comma operator to deal with the possibility of void returns from a user defined operator++. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
And where are they available, or at least can be read of?
Yes, did you look at http://lists.boost.org/MailArchives/boost/msg52178.php as I suggested? John.
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.
participants (4)
-
Agoston Bejo
-
David Abrahams
-
John Maddock
-
Wolfgang Meyer