[MPL] RFC: An MPL macro to define a has_member_xxx<T> predicate
If there's already a boost solution for this, then I have egg on my face, but I can't find one:
I'd like an MPL macro that defines a predicate template which inherits from boost::true_type iff the given type defines *any* member with a particular name (false_type otherwise), and which does not assume the member name exists, like this:
struct my_class {
// foo might be member data, member function, a typedef, etc:
int foo;
};
CREATE_MEMBER_CHECK(foo);
CREATE_MEMBER_CHECK(bar);
has_member_foo
AMDG On 10/31/2013 09:36 AM, Erik Erlandson wrote:
If there's already a boost solution for this, then I have egg on my face, but I can't find one:
Look at tti: http://www.boost.org/libs/tti/
I'd like an MPL macro that defines a predicate template which inherits from boost::true_type iff the given type defines *any* member with a particular name (false_type otherwise), and which does not assume the member name exists, like this:
struct my_class { // foo might be member data, member function, a typedef, etc: int foo; };
CREATE_MEMBER_CHECK(foo); CREATE_MEMBER_CHECK(bar);
has_member_foo
t1; // this inherits from true_type has_member_bar t2; // this inherits from false_type I wrote an implementation of the above, and example, here: https://gist.github.com/erikerlandson/7251015
The macro BOOST_MPL_HAS_XXX_TRAIT_DEF produces a predicate class that detects if a nested type exists, but only works for types, not other kinds of defined members. The class is_member_pointer<T>, but appears to require that you already know a symbol exists.
I suppose such a macro might be called BOOST_MPL_HAS_XXX_MEMBER_DEF.
In Christ, Steven Watanabe
----- Original Message -----
If there's already a boost solution for this, then I have egg on my face, but I can't find one:
Look at tti: http://www.boost.org/libs/tti/
Aha, serves me right for not having latest rev. Thank you!
I'd like an MPL macro that defines a predicate template which inherits from boost::true_type iff the given type defines *any* member with a particular name (false_type otherwise), and which does not assume the member name exists, like this:
struct my_class { // foo might be member data, member function, a typedef, etc: int foo; };
CREATE_MEMBER_CHECK(foo); CREATE_MEMBER_CHECK(bar);
has_member_foo
t1; // this inherits from true_type has_member_bar t2; // this inherits from false_type I wrote an implementation of the above, and example, here: https://gist.github.com/erikerlandson/7251015
The macro BOOST_MPL_HAS_XXX_TRAIT_DEF produces a predicate class that detects if a nested type exists, but only works for types, not other kinds of defined members. The class is_member_pointer<T>, but appears to require that you already know a symbol exists.
I suppose such a macro might be called BOOST_MPL_HAS_XXX_MEMBER_DEF.
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Erik Erlandson
-
Steven Watanabe