member_of: a pointer to member trait
Hello, I'm using BOOST libraries in my developments.
I need a trait returning the class type from a pointer to member type.
An example:
member_of
Bernabe Cantos
Hello, I'm using BOOST libraries in my developments.
I need a trait returning the class type from a pointer to member type.
An example:
member_of
::type // this equals to 'A' member_of ::type // this equals to 'B const' member_of ::type // this equals to an undefined struct I don't know if the functionality I need exists in BOOST. I hope so. If not, should it be difficult to provide? Maybe doing some modifications to is_member_function_pointer.
Thanks in advance
Assuming that BOOST has no member_of<> traits or similar, I made some little preprocessor macros to implement it. This is my first attempt with boost::preprocessor, so I'm asking if this can be improved easily. Variable arguments and calling conventions are ugly, I know, but I need them. #ifndef MEMBER_OF_MAX_PARAMS #define MEMBER_OF_MAX_PARAMS 12 #endif struct undefined { }; template<class TT> struct member_of { typedef undefined type; }; #define MEMBER_OF_impl(z, cv_, np_) \ template< \ class TT, class RT \ BOOST_PP_COMMA_IF(np_) BOOST_PP_ENUM_PARAMS(np_, class P) \
\ struct member_of< \ RT(MEMBER_OF_callconv TT::*MEMBER_OF_cv(cv_)) \ (BOOST_PP_ENUM_PARAMS(np_, P)MEMBER_OF_ellipsis(np_)) \ { \ typedef typename MEMBER_OF_cv(cv_) TT type; \ };
#define MEMBER_OF_cv(i) \ BOOST_PP_APPLY( \ BOOST_PP_TUPLE_ELEM(4, i, \ (BOOST_PP_NIL, (const), (volatile), (const volatile)) \ ) \ ) #define MEMBER_OF(z, n, unused) \ BOOST_PP_REPEAT(4, MEMBER_OF_impl, n) #undef MEMBER_OF_ellipsis #define MEMBER_OF_ellipsis(n) #undef MEMBER_OF_callconv #define MEMBER_OF_callconv BOOST_PP_REPEAT(MEMBER_OF_MAX_PARAMS, MEMBER_OF, ~) #undef MEMBER_OF_callconv #define MEMBER_OF_callconv __stdcall BOOST_PP_REPEAT(MEMBER_OF_MAX_PARAMS, MEMBER_OF, ~) #undef MEMBER_OF_callconv #define MEMBER_OF_callconv __cdecl BOOST_PP_REPEAT(MEMBER_OF_MAX_PARAMS, MEMBER_OF, ~) #undef MEMBER_OF_callconv #define MEMBER_OF_callconv #undef MEMBER_OF_ellipsis #define MEMBER_OF_ellipsis(n) BOOST_PP_COMMA_IF(n)... BOOST_PP_REPEAT(MEMBER_OF_MAX_PARAMS, MEMBER_OF, ~) #undef MEMBER_OF_ellipsis #undef MEMBER_OF_callconv #undef MEMBER_OF #undef MEMBER_OF_cv #undef MEMBER_OF_impl
participants (1)
-
Bernabe Cantos