Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-07 09:52:41

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_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 /* model for function_collection */
0034 
0035 template<typename Signature>
0036 struct function_model;
0037 
0038 /* is_terminal defined out-class to allow for partial specialization */
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 } /* namespace poly_collection::detail */
0126 
0127 } /* namespace poly_collection */
0128 
0129 } /* namespace boost */
0130 
0131 #endif