00001 #ifndef toast_iterator_dereference_iterator_hpp_INCLUDED
00002 #define toast_iterator_dereference_iterator_hpp_INCLUDED
00003
00004 #include <iterator>
00005 #include <boost/iterator/transform_iterator.hpp>
00006
00007 #include <toast/traits/pointer_traits.hpp>
00008
00015 namespace toast {
00016
00017 namespace detail {
00018
00019 template <typename Iterator>
00020 struct get_reference
00021 {
00022 typedef typename std::iterator_traits<Iterator>::value_type pointer_type;
00023 typedef typename pointer_traits<pointer_type>::reference_type result_type;
00024 result_type operator()(pointer_type pointer) const { return *pointer; }
00025 };
00026
00027 }
00028
00043 template <typename Iterator>
00044 class dereference_iterator
00045 : public boost::transform_iterator<detail::get_reference<Iterator>, Iterator>
00046 {
00047 public:
00048 explicit dereference_iterator(Iterator i)
00049 : boost::transform_iterator<detail::get_reference<Iterator>, Iterator>
00050 (boost::make_transform_iterator(i, detail::get_reference<Iterator>())) {}
00051 };
00052
00056 template <typename Iterator>
00057 dereference_iterator<Iterator> make_dereference_iterator(Iterator i)
00058 {
00059 return dereference_iterator<Iterator>(i);
00060 }
00061
00064 }
00065
00082 #endif // toast_iterator_dereference_iterator_hpp_INCLUDED