File indexing completed on 2025-11-07 09:52:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_POLY_COLLECTION_DETAIL_FUNCTION_MODEL_HPP
0010 #define BOOST_POLY_COLLECTION_DETAIL_FUNCTION_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/callable_wrapper.hpp>
0018 #include <boost/poly_collection/detail/callable_wrapper_iterator.hpp>
0019 #include <boost/poly_collection/detail/is_invocable.hpp>
0020 #include <boost/poly_collection/detail/segment_backend.hpp>
0021 #include <boost/poly_collection/detail/split_segment.hpp>
0022 #include <memory>
0023 #include <type_traits>
0024 #include <typeinfo>
0025 #include <utility>
0026
0027 namespace boost{
0028
0029 namespace poly_collection{
0030
0031 namespace detail{
0032
0033
0034
0035 template<typename Signature>
0036 struct function_model;
0037
0038
0039
0040 template<typename T>
0041 struct function_model_is_terminal:std::true_type{};
0042
0043 template<typename Signature>
0044 struct function_model_is_terminal<callable_wrapper<Signature>>:
0045 std::false_type{};
0046
0047 template<typename R,typename... Args>
0048 struct function_model<R(Args...)>
0049 {
0050 using value_type=callable_wrapper<R(Args...)>;
0051
0052 using type_index=std::type_info;
0053
0054 template<typename Callable>
0055 using is_implementation=is_invocable_r<R,Callable&,Args...>;
0056
0057 template<typename T>
0058 using is_terminal=function_model_is_terminal<T>;
0059
0060 template<typename T>
0061 static const std::type_info& index(){return typeid(T);}
0062
0063 template<typename T>
0064 static const std::type_info& subindex(const T&){return typeid(T);}
0065
0066 template<typename Signature>
0067 static const std::type_info& subindex(
0068 const callable_wrapper<Signature>& f)
0069 {
0070 return f.target_type();
0071 }
0072
0073 template<typename T>
0074 static void* subaddress(T& x){return boost::addressof(x);}
0075
0076 template<typename T>
0077 static const void* subaddress(const T& x){return boost::addressof(x);}
0078
0079 template<typename Signature>
0080 static void* subaddress(callable_wrapper<Signature>& f)
0081 {
0082 return f.data();
0083 }
0084
0085 template<typename Signature>
0086 static const void* subaddress(const callable_wrapper<Signature>& f)
0087 {
0088 return f.data();
0089 }
0090
0091 using base_iterator=callable_wrapper_iterator<value_type>;
0092 using const_base_iterator=callable_wrapper_iterator<const value_type>;
0093 using base_sentinel=value_type*;
0094 using const_base_sentinel=const value_type*;
0095 template<typename Callable>
0096 using iterator=Callable*;
0097 template<typename Callable>
0098 using const_iterator=const Callable*;
0099 template<typename Allocator>
0100 using segment_backend=detail::segment_backend<function_model,Allocator>;
0101 template<typename Callable,typename Allocator>
0102 using segment_backend_implementation=
0103 split_segment<function_model,Callable,Allocator>;
0104
0105 static base_iterator nonconst_iterator(const_base_iterator it)
0106 {
0107 return base_iterator{
0108 const_cast<value_type*>(static_cast<const value_type*>(it))};
0109 }
0110
0111 template<typename T>
0112 static iterator<T> nonconst_iterator(const_iterator<T> it)
0113 {
0114 return const_cast<iterator<T>>(it);
0115 }
0116
0117 private:
0118 template<typename,typename,typename>
0119 friend class split_segment;
0120
0121 template<typename Callable>
0122 static value_type make_value_type(Callable& x){return value_type{x};}
0123 };
0124
0125 }
0126
0127 }
0128
0129 }
0130
0131 #endif