You can opt out of templating Foowith std::functionand std::bind:
#include <functional>
#include <iostream>
void foo(int a, int b)
{
std::cout<<a<<b;
}
struct Foo
{
public:
template<typename... Args>
Foo(Args&&... args)
: func_(std::bind(foo, std::forward<Args>(args)...)) { }
void action(){ func_(); }
private:
std::function<void()> func_;
};
int main()
{
Foo x(1,2);
x.action();
}
EDIT: to respond to the comment, to bind the constructor, I would use a function template like
template<typename T, typename... Args> T *make_new(Args&&... args) {
return new T(std::forward<Args>(args)...);
}
and then
std::bind(make_new<SomeClass, Args...>, std::forward<Args>(args)...)
: std::make_shared std::make_unique ( ++ 14), .