bind2nd

std::bind2nd は参照を引数にとる関数を受け取れない。内部で参照の参照を引き起こすため。
http://www.radiumsoftware.com/0304.html#030417
http://boost.org/libs/functional/binders.html
誰でも一度はつきあたる問題みたい。

#include <iostream>
#include <vector>
#include <boost/functional.hpp>

using namespace std;

class Hoge
{
	int n;
public:
	explicit Hoge(int n_) { n = n_; }
	void print(ostream& os) const { os << n << ' '; }
};

int main(int argc, char *argv[])
{
	vector<Hoge> v;

	v.push_back(Hoge(2));
	v.push_back(Hoge(3));
	v.push_back(Hoge(5));
	v.push_back(Hoge(7));

	for_each(v.begin(), v.end(), boost::bind2nd(boost::mem_fun_ref(&Hoge::print), cout));

	return 0;
}