1 /* Copyright 2016-2017 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)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_ITERATOR_TRAITS_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_ITERATOR_TRAITS_HPP
17 #include <type_traits>
21 namespace poly_collection{
23 namespace common_impl{
25 template<typename Model,typename Allocator>
26 class poly_collection;
32 /* (Internal) bunch of traits-grouped functions for const-preserving
33 * interoperatibility between iterators and local iterators of a
37 template<typename Iterator>
38 struct poly_collection_of /* to be specialized for iterator impls */
43 template<typename PolyCollection>
46 template<typename Model,typename Allocator>
47 struct model_of<common_impl::poly_collection<Model,Allocator>>
52 template<typename Iterator>
53 struct iterator_traits
55 using container_type=typename poly_collection_of<Iterator>::type;
56 using is_const_iterator=typename std::is_const<
57 typename std::remove_reference<
58 typename std::iterator_traits<Iterator>::reference
61 using iterator=typename std::conditional<
62 is_const_iterator::value,
63 typename container_type::const_iterator,
64 typename container_type::iterator
66 using base_segment_info_iterator=typename std::conditional<
67 is_const_iterator::value,
68 typename container_type::const_base_segment_info_iterator,
69 typename container_type::base_segment_info_iterator
71 using local_base_iterator=typename std::conditional<
72 is_const_iterator::value,
73 typename container_type::const_local_base_iterator,
74 typename container_type::local_base_iterator
77 using local_iterator=typename std::conditional<
78 is_const_iterator::value,
79 typename container_type::template const_local_iterator<T>,
80 typename container_type::template local_iterator<T>
83 static base_segment_info_iterator
84 base_segment_info_iterator_from(iterator it)noexcept{return it.mapit;}
86 static base_segment_info_iterator
87 base_segment_info_iterator_from(local_base_iterator it)noexcept
90 static base_segment_info_iterator
91 end_base_segment_info_iterator_from(iterator it)noexcept{return it.mapend;}
93 static local_base_iterator
94 local_base_iterator_from(iterator it)noexcept
98 model_of<container_type>::type::nonconst_iterator(it.segpos)
104 local_base_iterator lbit,base_segment_info_iterator mapend)noexcept
106 return {lbit.mapit,mapend.base(),lbit.base()};
110 } /* namespace poly_collection::detail */
112 } /* namespace poly_collection */
114 } /* namespace boost */