Update: I got it to work with std::conditional :
template < class T, void (std::conditional<std::is_class<T>::value, T, struct dummy>::type::* ...FUNC)(int) > class holder;
Another possible solution is to use a subclass:
template < class T, void (T::*FUNC)(int) > class class_holder { public: typedef typename T::value_type value_type; public: explicit class_holder() : setter(FUNC) { std::cout << "func\n"; } protected: std::function<void (value_type&, int)> setter; } template <class T, bool IsClass = std::is_class<T>::value> class holder; template <class T> class holder<T, true> : public class_holder<T> { public: template <void (T::*FUNC)(int) > class with_member : public class_holder<T, FUNC> { }; }; template <class T> class holder<T, false> { public: explicit holder() { std::cout << "plain\n"; } }; int main() { holder<person> h1; holder<person>::with_member<&person::age> h2; holder<int> h3; }
I did not compile this, so tell me if something is not working.
source share