c++ - How to specialize for member function type in template class? -


i tested following codes, , find out std::is_function doesn't accept member function types.(i'm not sure if true other compilers, i'm using mvc++ nov 2012 ctp)

   class ac {     public:       float af(int) {}     };      int main() {      std::cout <<  std::is_function<decltype(ac::af)>::value << '\n'; //output 0     } 

so i'm trying implement it:

template<typename t> struct is_member_function : std::false_type {}; template<typename t, typename r, typename... args> struct is_member_function<r (t::) (args...)> : std::true_type {}; //this doesn't compile 

for member function pointer type, can specialize signature: r (t::*)(args...) , corresponding syntax member function type?

it appears, via link, following implmentation used is_member_function_pointer

template< class t > struct is_member_function_pointer_helper : std::false_type {};  template< class t, class u>  struct is_member_function_pointer_helper<t u::*> : std::is_function<t> {};  template< class t > struct is_member_function_pointer : is_member_function_pointer_helper<                                         typename std::remove_cv<t>::type                                     > {}; 

so can determine if member pointer of type u using t u::* , can determine if t function type. don't know of syntax member function type, member function pointer type. i'd have consult standard see if such type can exist.

if case not exist implement wrapper class added pointer so.

template<class t> struct is_member_function {     static const bool value = std::is_member_function_pointer<t*>::value; }; 

but when try decltype(some_type::some_member) error saying can't use some_type::some_member. '&' required

the following works function member pointers

std::is_member_function_pointer<decltype(&foo::hello)>::value 

it seems me can use member pointers , not member types.

an alternate implementation of above is_member_function_pointer_helper might like

template<class... args, class r, class u> struct is_member_function_pointer_helper<r (u::*)(args...)> : std::true_type {}; 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -