C++11 bind解决方案:
std::for_each(this->begin(), this->end(),
std::bind(&C::transformation, this, std::placeholders::_1));
C++11 lambda解决方案:
std::for_each(this->begin(), this->end(),
[this] (T& i) { transformation(i); });
C++14 泛型 lambda解决方案:
std::for_each(this->begin(), this->end(),
[this] (auto&& i) { transformation(std::forward<decltype(i)>(i)); });
C++98 绑定1st+mem_fun解决方案:
std::for_each(this->begin(), this->end(),
std::bind1st(std::mem_fun(&C::transformation), this));
Note: this->begin()
and this->end()
calls are qualified with this->
only because in the OP's code they are member functions of a templated base class. As such, those names are primirarily searched in a global namespace. Any other occurrence of this
is mandatory.