[MPL] has_xxx always returns false!

This code: BOOST_MPL_HAS_XXX_TRAIT_DEF(normal); template<class T, bool HasNormal> class getVertexHasNormal { public: static void getNormal(T &tv) {} }; template<class T> class getVertexHasNormal<T, true> // true case { public: static void getNormal(T &tv) { // do something } }; template<class VT> class A : public base { void doit(v) /* override */ { VT tv; getVertexHasNormal<VT, has_normal<VT>::value >::getNormal(tv); } } if I understand correctly, this code is suppose to do call a different "getNormal" method if the method "normal" exists (or not) in the template parameter class. Basically mimicking the infamous "__if_exists" macro on the Microsoft c++ compiler.... right? but, has_normal<VT> always return false (visual studio 2008) so we don't get the right expected behavior! Feel free to educate me.... thanks in advance. eric

AMDG Eric wrote:
This code:
BOOST_MPL_HAS_XXX_TRAIT_DEF(normal); <snip>
if I understand correctly, this code is suppose to do call a different "getNormal" method if the method "normal" exists (or not) in the template parameter class.
Basically mimicking the infamous "__if_exists" macro on the Microsoft c++ compiler.... right?
but, has_normal<VT> always return false (visual studio 2008) so we don't get the right expected behavior!
has_normal checks for a nested *type* called normal, not for a member function. #include <boost/mpl/has_xxx.hpp> #include <boost/mpl/assert.hpp> BOOST_MPL_HAS_XXX_TRAIT_DEF(normal); struct test1 {}; struct test2 { typedef void normal; }; struct test3 { int normal(); }; int main() { BOOST_MPL_ASSERT_NOT((has_normal<test1>)); BOOST_MPL_ASSERT((has_normal<test2>)); BOOST_MPL_ASSERT_NOT((has_normal<test3>)); } In Christ, Steven Watanabe

Steven Watanabe <watanabesj <at> gmail.com> writes: right. Is there a way to check if a method exists (a true replacement of __if_exists) ? eric l.

Hi,
"scuzez-moi" but... (a real newbie here)... where should I look again ?
thanks for helping!
https://svn.boost.org/trac/boost/browser/sandbox/introspection
eric l.
-- Murilo Adriano Vasconcelos http://murilo.wordpress.com

Sorry, it's in the vault.
Check my introspection code in the sandbox ;)
"scuzez-moi" but... (a real newbie here)... where should I look again ?
thanks for helping!
eric l.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
Eric
-
joel falcou
-
Joel.Falcou@lri.fr
-
Murilo Adriano Vasconcelos
-
Steven Watanabe