stl - Keys / Values Functionality to Iterators in C++ -


I know that these questions have come in different slopes before, but this is slightly different.

I is a class that contains the std :: map, though I want to use the class in the map for other purposes, outwardly, I can only mark an Iterator adapter with values ​​within the map (like Study: : The second thing in the pair).

Example in Python I can do something like this:

  def __iter __ (self): return self.Danks.Features ()  

How can I do this by being implemented in C ++?

Thanks,

Donation

Take a look at Boost Insert that provides this functionality:

  template & lt; Typename K, typename V & gt; Struct get_value {Const V & amp; Operator () (STD :: Jodi and LT; K, V & P; Const & P) {Return P. Sext; }}; Square your_class {typedef map & lt; Int, float & gt; TMap; TMAP Mimeup; Public: typedef get_value & lt; TMap :: key_type, TMap :: data_type & gt; F, Type-Ff boost :: Transformer & lt; F, TMap :: Iterator & gt; Value_iterator; Value_iterator start () {return make_transform_iterator (mymap.begin (), F ()); } Value_iterator end () {return make_transform_iterator (mymap.end), F ()); } // The same for the TODO const versions // the rest of the interface ...};  

You can now iterate over the values, e.g. Like this:

  your_class c; // fill c with some values ​​... copy (c.begin (), c.end (), ostream_iterator & lt; float> (cout, ""));  

Comments