Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:45:57

0001 /* Copyright 2016-2024 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/poly_collection for library home page.
0007  */
0008 
0009 #ifndef BOOST_POLY_COLLECTION_DETAIL_ITERATOR_TRAITS_HPP
0010 #define BOOST_POLY_COLLECTION_DETAIL_ITERATOR_TRAITS_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <iterator>
0017 #include <type_traits>
0018 
0019 namespace boost{
0020 
0021 namespace poly_collection{
0022 
0023 namespace common_impl{
0024 
0025 template<typename Model,typename Allocator>
0026 class poly_collection;
0027 
0028 }
0029 
0030 namespace detail{
0031 
0032 /* (Internal) bunch of traits-grouped functions for const-preserving
0033  * interoperatibility between iterators and local iterators of a
0034  * poly_collection, plus access to associated model's index from
0035  * an iterator type.
0036  */
0037 
0038 template<typename Iterator>
0039 struct poly_collection_of /* to be specialized for iterator impls */
0040 {
0041  using type=void;
0042 };
0043 
0044 template<typename PolyCollection>
0045 struct model_of;
0046 
0047 template<typename Model,typename Allocator>
0048 struct model_of<common_impl::poly_collection<Model,Allocator>>
0049 {
0050   using type=Model;
0051 };
0052 
0053 template<typename Iterator>
0054 struct iterator_traits
0055 {
0056   using container_type=typename poly_collection_of<Iterator>::type;
0057   using model_type=typename model_of<container_type>::type;
0058   using type_index=typename container_type::type_index;
0059   using is_const_iterator=typename std::is_const<
0060     typename std::remove_reference<
0061       typename std::iterator_traits<Iterator>::reference
0062     >::type
0063   >::type;
0064   using iterator=typename std::conditional<
0065     is_const_iterator::value,
0066     typename container_type::const_iterator,   
0067     typename container_type::iterator
0068   >::type;
0069   using base_segment_info_iterator=typename std::conditional<
0070     is_const_iterator::value,
0071     typename container_type::const_base_segment_info_iterator,   
0072     typename container_type::base_segment_info_iterator
0073   >::type;
0074   using local_base_iterator=typename std::conditional<
0075     is_const_iterator::value,
0076     typename container_type::const_local_base_iterator,   
0077     typename container_type::local_base_iterator
0078   >::type;
0079   template<typename T>
0080   using local_iterator=typename std::conditional<
0081     is_const_iterator::value,
0082     typename container_type::template const_local_iterator<T>,   
0083     typename container_type::template local_iterator<T>
0084   >::type;
0085 
0086   static base_segment_info_iterator
0087   base_segment_info_iterator_from(iterator it)noexcept{return it.mapit;} 
0088 
0089   static base_segment_info_iterator
0090   base_segment_info_iterator_from(local_base_iterator it)noexcept
0091     {return it.mapit;}
0092 
0093   static base_segment_info_iterator
0094   end_base_segment_info_iterator_from(iterator it)noexcept{return it.mapend;} 
0095 
0096   static local_base_iterator
0097   local_base_iterator_from(iterator it)noexcept
0098   {
0099     return {it.mapit,model_type::nonconst_iterator(it.segpos)};
0100   }
0101 
0102   static iterator 
0103   iterator_from(
0104     local_base_iterator lbit,base_segment_info_iterator mapend)noexcept
0105   {
0106     return {lbit.mapit,mapend.base(),lbit.base()};
0107   }
0108 
0109   template<typename T>
0110   static decltype(model_type::template index<T>()) index()
0111   {
0112     return model_type::template index<T>();
0113   }
0114 };
0115 
0116 } /* namespace poly_collection::detail */
0117 
0118 } /* namespace poly_collection */
0119 
0120 } /* namespace boost */
0121 
0122 #endif