相关疑难解决方法(0)

从成员函数指针类型生成仿函数

我试图简化(通过make_fn())wrap()为arity n的成员函数预处理参数(via )的仿函数的生成.
生成仿函数基本上是可行的,但直到现在只能通过显式指定成员函数的参数类型.
现在我想从它处理的成员函数类型生成正确的函子:

struct X {};

template<class C, typename T1, bool (C::*F)(T1)>
inline // there are more for T1..TN
bool wrap(C* c, X x) 
{
    return (c->*F)(process<T1>(x));
}

template<class C, typename T1, bool (C::*F)(T1)> 
inline // there are more for T1..TN
boost::function<bool (C*, X)> make_fn(F f) // <- problem here, F is not a type
{
    return boost::bind(&wrap<C, T1, F>, _1, _2);
}
Run Code Online (Sandbox Code Playgroud)

但是,有了这个,vc ++和g ++看不到F参数的类型make_fn().我必须在这里错过一些明显的东西,感觉有些失明.

这个想法应该是这样的:

struct A …
Run Code Online (Sandbox Code Playgroud)

c++ templates functor

5
推荐指数
1
解决办法
2018
查看次数

标签 统计

c++ ×1

functor ×1

templates ×1