| 1 | /* Copyright 2016 Joaquin M Lopez Munoz. |
| 2 | * Distributed under the Boost Software License, Version 1.0. |
| 3 | * (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | * http://www.boost.org/LICENSE_1_0.txt) |
| 5 | * |
| 6 | * See http://www.boost.org/libs/poly_collection for library home page. |
| 7 | */ |
| 8 | |
| 9 | #ifndef BOOST_POLY_COLLECTION_DETAIL_AUTO_ITERATOR_HPP |
| 10 | #define BOOST_POLY_COLLECTION_DETAIL_AUTO_ITERATOR_HPP |
| 11 | |
| 12 | #if defined(_MSC_VER) |
| 13 | #pragma once |
| 14 | #endif |
| 15 | |
| 16 | #include <boost/iterator/iterator_adaptor.hpp> |
| 17 | |
| 18 | namespace boost{ |
| 19 | |
| 20 | namespace poly_collection{ |
| 21 | |
| 22 | namespace detail{ |
| 23 | |
| 24 | /* auto_iterator<Iterator> (for want of a better name) behaves like Iterator |
| 25 | * save for the fact that it derefs to Iterator& rather than |
| 26 | * Iterator::reference. This is useful to "lift" std algorithms so that |
| 27 | * user-defined predicates are passed iterators that can then be dereferenced |
| 28 | * internally. |
| 29 | */ |
| 30 | |
| 31 | template<typename Iterator> |
| 32 | class auto_iterator: |
| 33 | public boost::iterator_adaptor<auto_iterator<Iterator>,Iterator,Iterator> |
| 34 | { |
| 35 | public: |
| 36 | auto_iterator()=default; |
| 37 | auto_iterator(const Iterator& it):auto_iterator::iterator_adaptor_{it}{} |
| 38 | auto_iterator(const auto_iterator&)=default; |
| 39 | auto_iterator& operator=(const auto_iterator&)=default; |
| 40 | |
| 41 | private: |
| 42 | friend class boost::iterator_core_access; |
| 43 | |
| 44 | Iterator& dereference()const noexcept |
| 45 | { |
| 46 | return const_cast<auto_iterator*>(this)->base_reference(); |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | } /* namespace poly_collection::detail */ |
| 51 | |
| 52 | } /* namespace poly_collection */ |
| 53 | |
| 54 | } /* namespace boost */ |
| 55 | |
| 56 | #endif |
| 57 | |