00001 #ifndef toast_iterator_first_iterator_hpp_INCLUDED
00002 #define toast_iterator_first_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_first
00020 {
00021 typedef typename std::iterator_traits<Iterator>::reference pair_reference;
00022 typedef typename pair_ref_traits<pair_reference>::first_type& result_type;
00023 result_type operator()(pair_reference pair) const { return pair.first; }
00024 };
00025
00026 }
00027
00040 template <typename Iterator>
00041 class first_iterator
00042 : public boost::transform_iterator<detail::get_first<Iterator>, Iterator>
00043 {
00044 public:
00045 explicit first_iterator(Iterator i)
00046 : boost::transform_iterator<detail::get_first<Iterator>, Iterator>
00047 (boost::make_transform_iterator(i, detail::get_first<Iterator>())) {}
00048 };
00049
00053 template <typename Iterator>
00054 first_iterator<Iterator> make_first_iterator(Iterator i)
00055 {
00056 return first_iterator<Iterator>(i);
00057 }
00058
00063 }
00064
00065 #endif // toast_iterator_first_iterator_hpp_INCLUDED