前のやつできました.
これの下のバージョンができました.
http://d.hatena.ne.jp/graighle/20080511/1210536299
#include <iostream> #include <map> #include <vector> #include <algorithm> #include <boost/bind.hpp> // イテレータの指す先を返す template<class IT> struct unref : std::unary_funtion<IT, typename std::iterator_traits<IT>::value_type> { const typename std::unary_function<IT>::value_type& operator()(const IT& x) const{ return *x; } }; struct test { void draw(int x) const{ // showじゃなくてdrawだったw std::cout << x << std::endl; } }; int main(){ typedef std::map<int, object> my_map; typedef my_map::value_type my_pair; typedef my_map::const_iterator my_iter; std::map<int, test> m; // まぁこの例だとstd::mapの意味はないですがw m[0] = test(); m[1] = test(); m[2] = test(); // これはできた(5はてきとう) std::for_each(m.begin(), m.end(), boost::bind(&test::draw, boost::bind(&my_pair::second, _1), 5)); typedef std::map<int, test>::const_iterator map_it_t; vector<map_it_t> v; for(map_it_t it = m.begin(); it != m.end(); ++it) v.push_back(it); // これはだめ //std::for_each(v.begin(), v.end(), boost::bind(&(std::vector<map_it_t>::iterator_type?::...::draw), _1, t)); // これでおk std::for_each(v.begin(), v.end(), boost::bind( &test::draw, boost::bind( &my_pair::second, boost::bind( unref<my_iter>(), // ここで最初に参照はがし _1 ) ), 5 ) ); return 0; }
なんとなくだけどbindが分かってきた.
bind入門講座みたいになってきた?w