std :: function到可变参数成员函数,然后绑定可变参数模板参数

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...);

}

};

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容