Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:55:09

0001 /* Copyright 2016-2018 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   template<typename Callable>
0053   using is_implementation=is_invocable_r<R,Callable&,Args...>;
0054 
0055   template<typename T>
0056   using is_terminal=function_model_is_terminal<T>;
0057 
0058   template<typename T>
0059   static const std::type_info& subtypeid(const T&){return typeid(T);}
0060 
0061   template<typename Signature>
0062   static const std::type_info& subtypeid(
0063     const callable_wrapper<Signature>& f)
0064   {
0065     return f.target_type();
0066   }
0067 
0068   template<typename T>
0069   static void* subaddress(T& x){return boost::addressof(x);}
0070 
0071   template<typename T>
0072   static const void* subaddress(const T& x){return boost::addressof(x);}
0073 
0074   template<typename Signature>
0075   static void* subaddress(callable_wrapper<Signature>& f)
0076   {
0077     return f.data();
0078   }
0079   
0080   template<typename Signature>
0081   static const void* subaddress(const callable_wrapper<Signature>& f)
0082   {
0083     return f.data();
0084   }
0085 
0086   using base_iterator=callable_wrapper_iterator<value_type>;
0087   using const_base_iterator=callable_wrapper_iterator<const value_type>;
0088   using base_sentinel=value_type*;
0089   using const_base_sentinel=const value_type*;
0090   template<typename Callable>
0091   using iterator=Callable*;
0092   template<typename Callable>
0093   using const_iterator=const Callable*;
0094   template<typename Allocator>
0095   using segment_backend=detail::segment_backend<function_model,Allocator>;
0096   template<typename Callable,typename Allocator>
0097   using segment_backend_implementation=
0098     split_segment<function_model,Callable,Allocator>;
0099 
0100   static base_iterator nonconst_iterator(const_base_iterator it)
0101   {
0102     return base_iterator{
0103       const_cast<value_type*>(static_cast<const value_type*>(it))};
0104   }
0105 
0106   template<typename T>
0107   static iterator<T> nonconst_iterator(const_iterator<T> it)
0108   {
0109     return const_cast<iterator<T>>(it);
0110   }
0111 
0112 private:
0113   template<typename,typename,typename>
0114   friend class split_segment;
0115 
0116   template<typename Callable>
0117   static value_type make_value_type(Callable& x){return value_type{x};}
0118 };
0119 
0120 } /* namespace poly_collection::detail */
0121 
0122 } /* namespace poly_collection */
0123 
0124 } /* namespace boost */
0125 
0126 #endif