I have a std::map<std::string, MyObject> and want to iterate over it calling several member functions of MyObject. This seems like a good case to learn about transform/projection iterator, but I am having a hard time getting a compiling example. My most recent attempt looks like this: class MyObject { public: void CommitChanges(); void RollbackChanges(); // More implementation details would follow }; typedef std::map<std::string, MyObject> MyMap; typedef MyMap::iterator MyIterator; typedef MyMap::value_type mapped_type; typedef boost::projection_iterator_generator< Select2ndRef<mapped_type>, MyIterator >::type projection; MyMap theMap; projection begin( theMap.begin() ); projection end( theMap.begin() ); for_each( begin, end, mem_fun_ref( MyObject::CommitChanges ) ); I also have the following two templates, although I suspect their equivalent must be lurking in boost somewhere: template<class pair_type> struct Select1stRef { typedef typename pair_type::first_type & result_type; result_type operator()( pair_type &source ) const { return source.first; } }; template<class pair_type> struct Select2ndRef { typedef typename pair_type::second_type & result_type; result_type operator()( pair_type &source ) const { return source.second; } }; I am compiling using BCB5 compiler in the IDE, should be equivalent to the free 5.5.1 command line compiler. While I could simply write a forwarding functor in a fraction of the time it will take me to solve this, there is definitely a ne tool I would like to add to my toolbox here once I understand what is happenning. Unfortunately I am getting somewhat lost in reference-to-reference issues, and the occasional compiler crash does not help. Any and all hints appreciated -- AlisdairM
participants (1)
-
Alisdair Meredith