为 std::bind 创建模板包装器
Creating A Template Wrapper for std::bind
我正在尝试为 std::bind 创建一个简单的包装函数,它将采用一个成员函数。
template<typename T, typename F>
void myBindFunction(T &t)
{
std::bind(T::F, t );
}
MyClass a = MyClass();
myBindFunction <MyClass, &MyClass::m_Function>( a );
我不确定我想要实现的目标是否可行?
您可以将第二个模板参数设置为非类型模板参数,即成员函数指针。
template<typename T, void(T::*F)()>
void myBindFunction(T &t)
{
std::bind(F, t); // bind the member function pointer with the object t
}
住
相关文章:
- 如何在c++17中制作一个模板包装器/装饰器
- std::vector的包装器,使数组的结构看起来像结构的数组
- 如何在c++迭代器类型中包装std::chrono
- 是否可以用"iostream"包装现有的TCP/OOpenSSL会话
- 用pybind11包装C++抽象类时出错
- 为左值和右值的包装器实现C++范围
- C结构,其指针将被包装在unique_ptr中
- 如何包装第三方DLL在R中使用
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 将 N-arg 函数包装到另一个函数中
- 元组由 Swig 生成的 Python 包装器返回,用于C++向量
- 包装一个对象并假装它是一个 int
- 使用 Python Extension API 包装复杂C++类
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 包装C++类时不完整的类型 GLFWwindow
- 将函数包装器转换为 std::function
- C++函数包装器来捕获某些信号
- 创建包装升压适配器的自定义范围类
- 如何包装(撰写)增强 hana 地图并访问括号运算符(运算符 [])?
- 满意和建模的概念?