Have a look at Boost's transform_iterator
which provides exactly this kind of functionality:
template <typename K, typename V>
struct get_value {
const V& operator ()(std::pair<K, V> const& p) { return p.second; }
};
class your_class {
typedef map<int, float> TMap;
TMap mymap;
public:
typedef get_value<TMap::key_type, TMap::data_type> F;
typedef
boost::transform_iterator<F, TMap::iterator>
value_iterator;
value_iterator begin() { return make_transform_iterator(mymap.begin(), F()); }
value_iterator end() { return make_transform_iterator(mymap.end(), F()); }
// TODO Same for const versions.
// Rest of the interface …
};
Now you can iterate over the values, e.g. like this:
your_class c;
// Fill c with some values …
copy(c.begin(), c.end(), ostream_iterator<float>(cout, " "));