Boost logo

Boost :

From: Brock Peabody (brock.peabody_at_[hidden])
Date: 2003-11-13 15:35:46


Is anyone interested in a generic facility for member detection? I couldn't
find anything in boost to do it (though there was some discussion about it a
while ago: http://lists.boost.org/MailArchives/boost/msg27338.php). What
I've got looks like:

For types:

   BOOST_MAKE_HAS_MEMBER_TYPE(result_type)

   struct s { typedef s result_type; };
   struct t {};

   BOOST_STATIC_ASSERT(has_member_type_result_type<s>::value)
   BOOST_STATIC_ASSERT(!has_member_type_result_type<t>::value)

For member functions

   BOOST_MAKE_HAS_MEMBER_FUNCTION(
      f, //name
      int, //return type
      (2, (int, double)), //parameters
      0 //0 if not const
   )

   struct s { int f(int,double); };
   struct t { typedef int f; };
   struct u {};
   struct v { int f(int,double) const; };

   BOOST_STATIC_ASSERT(has_member_function_f<s>::value)
   BOOST_STATIC_ASSERT(!has_member_function_f<t>::value)
   BOOST_STATIC_ASSERT(!has_member_function_f<u>::value)
   BOOST_STATIC_ASSERT(!has_member_function_f<v>::value)

The same thing could be done for data members, static functions, and static
members.

It's not the prettiest thing in the world, and function signatures have to
match exactly, but if any of you think its better than doing it by hand
every time I'll post the code and some documentation.

Brock


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk