Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 自动推断bind1st的类型(mem_-fun(&my_-class::f),这是什么?_C++_Templates_Stl_Functional Programming_Functor - Fatal编程技术网

C++ 自动推断bind1st的类型(mem_-fun(&my_-class::f),这是什么?

C++ 自动推断bind1st的类型(mem_-fun(&my_-class::f),这是什么?,c++,templates,stl,functional-programming,functor,C++,Templates,Stl,Functional Programming,Functor,我想把bind1stmem\u fun&我的类::f,这个函子分别传递给for\u。不幸的是,它很难阅读,因此我想给它一个更易于阅读的名称,如下所示: (the type I am looking for) meaningful_name = bind1st(mem_fun(&my_class::f), this); for_each(v.begin(), v.end(), meaningful_name); 有没有一种简单的方法来推断函子的类型?我知道mem_fun正是因为这个原因

我想把bind1stmem\u fun&我的类::f,这个函子分别传递给for\u。不幸的是,它很难阅读,因此我想给它一个更易于阅读的名称,如下所示:

(the type I am looking for) meaningful_name = bind1st(mem_fun(&my_class::f), this);

for_each(v.begin(), v.end(), meaningful_name);

有没有一种简单的方法来推断函子的类型?我知道mem_fun正是因为这个原因为我们节省了很多痛苦。

不,没有简单的方法。类型名称将相当长,甚至更不可读。如果您使用boost,就不需要使用boost\u AUTO,因为您可以只使用boost::bind并使其可读,而不需要本地文件

for_each(v.begin(), v.end(), boost::bind(&my_class::f, this));

不,没有简单的方法。类型名称将相当长,甚至更不可读。如果您使用boost,就不需要使用boost\u AUTO,因为您可以只使用boost::bind并使其可读,而不需要本地文件

for_each(v.begin(), v.end(), boost::bind(&my_class::f, this));

这取决于my_类的参数和返回类型:f。如果函数是

T my_class::f(A arg)
那你需要

binder1st<mem_fun1_t<T,my_class,A> > meaningful_name = bind1st(mem_fun(&my_class::f), this);

这取决于my_类的参数和返回类型:f。如果函数是

T my_class::f(A arg)
那你需要

binder1st<mem_fun1_t<T,my_class,A> > meaningful_name = bind1st(mem_fun(&my_class::f), this);
差不多:应该是mem_fun,而不是mem_fun。差不多:应该是mem_fun,而不是mem_fun。