00001 #ifndef toast_iterator_second_iterator_hpp_INCLUDED
00002 #define toast_iterator_second_iterator_hpp_INCLUDED
00003
00004 #include <iterator>
00005 #include <boost/iterator/transform_iterator.hpp>
00006 #include <toast/traits/pair_ref_traits.hpp>
00007
00014 namespace toast {
00015
00016 namespace detail {
00017
00018 template <typename Iterator>
00019 struct get_second
00020 {
00021 typedef typename std::iterator_traits<Iterator>::reference pair_reference;
00022 typedef typename pair_ref_traits<pair_reference>::second_type& result_type;
00023 result_type operator()(pair_reference pair) const { return pair.second; }
00024 };
00025
00026 }
00027
00040 template <typename Iterator>
00041 class second_iterator
00042 : public boost::transform_iterator<detail::get_second<Iterator>, Iterator>
00043 {
00044 public:
00045 explicit second_iterator(Iterator i)
00046 : boost::transform_iterator<detail::get_second<Iterator>, Iterator>
00047 (boost::make_transform_iterator(i, detail::get_second<Iterator>())) {}
00048 };
00049
00053 template <typename Iterator>
00054 second_iterator<Iterator> make_second_iterator(Iterator i)
00055 {
00056 return second_iterator<Iterator>(i);
00057 }
00058
00061 }
00062
00063 #endif // toast_iterator_second_iterator_hpp_INCLUDED