std :: function到可变参数成员函数,然后绑定可变参
2020-05-29 本文已影响0人
Aska偶阵雨
using namespace std;
class Foo
{
public:
template<typename... T>
void Init(T&... args)
{
cout << __FUNCTION__ << endl;
Print(args...);
using pmf_type = void (Foo::*)(T&...);
mf_ = std::bind((pmf_type)&Foo::Reset, this, args...);
}
template<typename... T>
void Reset(T&... args)
{
cout << __FUNCTION__ << endl;
Print(args...);
}
std::function<void()> mf_;
private:
template<typename F>
void Print(F&& arg)
{
cout << arg << endl;
}
template<typename First, typename... Rest>
void Print(First&& arg, Rest&&... args)
{
cout << arg;
Print(args...);
}
};