我想传递一个mem_fn
参数,bind
但编译器似乎不允许它。
例如,这很好用:
accumulate(cbegin(foos), cend(foos), 0, bind(plus<int>(), placeholders::_1, bind(&foo::r, placeholders::_2)));
但是当我尝试使用mem_fn
仿函数时,我得到了一页错误:
accumulate(cbegin(foos), cend(foos), 0, bind(plus<int>(), placeholders::_1, mem_fn(&foo::r)));
/usr/include/c++/6/bits/stl_numeric.h:在 '_Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation) 的实例化中 [with _InputIterator = __gnu_cxx::__normal_iterator >; _Tp = int; _BinaryOperation = std::_Bind(std::_Placeholder<1>, std::_Mem_fn)>]':
prog.cpp:20:102: 这里需要
/usr/include/c++/6/bits/stl_numeric.h: 154:22:错误:不匹配调用 '(std::_Bind(std::_Placeholder<1>, std::_Mem_fn)>) (int&, foo* const&)'</p>