I have the following working code:
class person
{
private:
int age_;
public:
person() : age_(56) {}
void age(int a) { age_ = i; }
}
template < class T, void (T::* ...FUNC)(int) > class holder;
template < class T, void (T::*FUNC)(int)>
class holder<T, FUNC>
{
public:
typedef typename T::value_type value_type;
public:
explicit holder() : setter(FUNC) { std::cout << "func\n"; }
private:
std::function<void (value_type&, int)> setter;
};
template < class T>
class holder<T>
{
public:
explicit holder() { std::cout << "plain\n"; }
};
int main()
{
holder<person> h1;
holder<person, &person::age> h2;
// this does not work:
holder<int> h3;
}
I know that in case of int (or any other non class, struct or union type) the code does not work because of the expect member function in the second template argument.
My question is how to change the code to make it work. I need it work that way, to make the use of my holder class simple.
I've tried it with type traits and also moved the member function pointer to the constructor of the class. Without success.
Any suggestions? Thanks in advance!