Brian Silverman | 5962333 | 2018-08-04 23:36:56 -0700 | [diff] [blame^] | 1 | |
| 2 | [section:iterator_traits Iterator Traits] |
| 3 | |
| 4 | `std::iterator_traits` provides access to five associated types |
| 5 | of any iterator: its `value_type`, `reference`, `pointer`, |
| 6 | `iterator_category`, and `difference_type`. Unfortunately, |
| 7 | such a "multi-valued" traits template can be difficult to use in a |
| 8 | metaprogramming context. `<boost/iterator/iterator_traits.hpp>` |
| 9 | provides access to these types using a standard metafunctions_. |
| 10 | |
| 11 | [h2 Synopsis] |
| 12 | |
| 13 | Header `<boost/iterator/iterator_traits.hpp>`: |
| 14 | |
| 15 | template <class Iterator> |
| 16 | struct iterator_value |
| 17 | { |
| 18 | typedef typename |
| 19 | std::iterator_traits<Iterator>::value_type |
| 20 | type; |
| 21 | }; |
| 22 | |
| 23 | template <class Iterator> |
| 24 | struct iterator_reference |
| 25 | { |
| 26 | typedef typename |
| 27 | std::iterator_traits<Iterator>::reference |
| 28 | type; |
| 29 | }; |
| 30 | |
| 31 | template <class Iterator> |
| 32 | struct iterator_pointer |
| 33 | { |
| 34 | typedef typename |
| 35 | std::iterator_traits<Iterator>::pointer |
| 36 | type; |
| 37 | }; |
| 38 | |
| 39 | template <class Iterator> |
| 40 | struct iterator_difference |
| 41 | { |
| 42 | typedef typename |
| 43 | detail::iterator_traits<Iterator>::difference_type |
| 44 | type; |
| 45 | }; |
| 46 | |
| 47 | template <class Iterator> |
| 48 | struct iterator_category |
| 49 | { |
| 50 | typedef typename |
| 51 | detail::iterator_traits<Iterator>::iterator_category |
| 52 | type; |
| 53 | }; |
| 54 | |
| 55 | [endsect] |