006
09.09.2010, 21:15 Uhr
0xdeadbeef
Gott (Operator)
|
Etwas in der Art vielleicht?
C++: |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <boost/iterator/transform_iterator.hpp>
#include <tr1/functional>
#include <algorithm> #include <iostream> #include <iterator> #include <map>
template<typename pair_t> struct pair_second_getter { typedef typename pair_t::second_type result_type;
typename pair_t::second_type operator()(pair_t const &p) const { return p.second; } };
template<typename iterator_t> struct map_value_iterator : boost::transform_iterator<pair_second_getter<typename std::iterator_traits<iterator_t>::value_type>, iterator_t> { map_value_iterator(iterator_t iter) : boost::transform_iterator<pair_second_getter<typename std::iterator_traits<iterator_t>::value_type>, iterator_t>(iter, pair_second_getter<typename std::iterator_traits<iterator_t>::value_type>()) { } };
template<typename T1, typename T2> struct map_value_iterators { typedef map_value_iterator<typename std::map<T1, T2>:: iterator> iterator; typedef map_value_iterator<typename std::map<T1, T2>:: const_iterator> const_iterator; typedef map_value_iterator<typename std::map<T1, T2>:: reverse_iterator> reverse_iterator; typedef map_value_iterator<typename std::map<T1, T2>::const_reverse_iterator> const_reverse_iterator; };
int main() { std::map<int, int> m;
m[1] = 3; m[2] = 1; m[3] = 4; m[4] = 1;
std::copy(map_value_iterators<int, int>::const_iterator(m.begin()), map_value_iterators<int, int>::const_iterator(m.end()), std::ostream_iterator<int>(std::cout, "\n"));
std::copy(map_value_iterators<int, int>::const_reverse_iterator(m.rbegin()), map_value_iterators<int, int>::const_reverse_iterator(m.rend()), std::ostream_iterator<int>(std::cout, "\n")); }
|
-- Einfachheit ist Voraussetzung für Zuverlässigkeit. -- Edsger Wybe Dijkstra |