File indexing completed on 2025-09-15 08:48:25
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_POLY_COLLECTION_DETAIL_BASE_MODEL_HPP
0010 #define BOOST_POLY_COLLECTION_DETAIL_BASE_MODEL_HPP
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/core/addressof.hpp>
0017 #include <boost/poly_collection/detail/is_final.hpp>
0018 #include <boost/poly_collection/detail/packed_segment.hpp>
0019 #include <boost/poly_collection/detail/stride_iterator.hpp>
0020 #include <memory>
0021 #include <type_traits>
0022 #include <typeinfo>
0023 #include <utility>
0024
0025 namespace boost{
0026
0027 namespace poly_collection{
0028
0029 namespace detail{
0030
0031
0032
0033 template<typename Base>
0034 struct base_model
0035 {
0036 using value_type=Base;
0037 using type_index=std::type_info;
0038 template<typename Derived>
0039 using is_implementation=std::is_base_of<Base,Derived>;
0040 template<typename T>
0041 using is_terminal=is_final<T>;
0042
0043 private:
0044 template<typename T>
0045 using enable_if_not_terminal=
0046 typename std::enable_if<!is_terminal<T>::value>::type*;
0047 template<typename T>
0048 using enable_if_terminal=
0049 typename std::enable_if<is_terminal<T>::value>::type*;
0050
0051 public:
0052 template<typename T>
0053 static const std::type_info& index(){return typeid(T);}
0054
0055 template<typename T,enable_if_not_terminal<T> =nullptr>
0056 static const std::type_info& subindex(const T& x){return typeid(x);}
0057
0058 template<typename T,enable_if_terminal<T> =nullptr>
0059 static const std::type_info& subindex(const T&){return typeid(T);}
0060
0061 template<typename T,enable_if_not_terminal<T> =nullptr>
0062 static void* subaddress(T& x)
0063 {
0064 return dynamic_cast<void*>(boost::addressof(x));
0065 }
0066
0067 template<typename T,enable_if_not_terminal<T> =nullptr>
0068 static const void* subaddress(const T& x)
0069 {
0070 return dynamic_cast<const void*>(boost::addressof(x));
0071 }
0072
0073 template<typename T,enable_if_terminal<T> =nullptr>
0074 static void* subaddress(T& x){return boost::addressof(x);}
0075
0076 template<typename T,enable_if_terminal<T> =nullptr>
0077 static const void* subaddress(const T& x){return boost::addressof(x);}
0078
0079 using base_iterator=stride_iterator<Base>;
0080 using const_base_iterator=stride_iterator<const Base>;
0081 using base_sentinel=Base*;
0082 using const_base_sentinel=const Base*;
0083 template<typename Derived>
0084 using iterator=Derived*;
0085 template<typename Derived>
0086 using const_iterator=const Derived*;
0087 template<typename Allocator>
0088 using segment_backend=detail::segment_backend<base_model,Allocator>;
0089 template<typename Derived,typename Allocator>
0090 using segment_backend_implementation=
0091 packed_segment<base_model,Derived,Allocator>;
0092
0093 static base_iterator nonconst_iterator(const_base_iterator it)
0094 {
0095 return {
0096 const_cast<value_type*>(static_cast<const value_type*>(it)),
0097 it.stride()
0098 };
0099 }
0100
0101 template<typename T>
0102 static iterator<T> nonconst_iterator(const_iterator<T> it)
0103 {
0104 return const_cast<iterator<T>>(it);
0105 }
0106
0107 private:
0108 template<typename,typename,typename>
0109 friend class packed_segment;
0110
0111 template<typename Derived>
0112 static const Base* value_ptr(const Derived* p)noexcept
0113 {
0114 return p;
0115 }
0116 };
0117
0118 }
0119
0120 }
0121
0122 }
0123
0124 #endif