]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/poly_collection/detail/function_model.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / poly_collection / detail / function_model.hpp
1 /* Copyright 2016-2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/poly_collection for library home page.
7 */
8
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_FUNCTION_MODEL_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_FUNCTION_MODEL_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <boost/core/addressof.hpp>
17 #include <boost/poly_collection/detail/callable_wrapper.hpp>
18 #include <boost/poly_collection/detail/callable_wrapper_iterator.hpp>
19 #include <boost/poly_collection/detail/is_invocable.hpp>
20 #include <boost/poly_collection/detail/segment_backend.hpp>
21 #include <boost/poly_collection/detail/split_segment.hpp>
22 #include <memory>
23 #include <type_traits>
24 #include <typeinfo>
25 #include <utility>
26
27 namespace boost{
28
29 namespace poly_collection{
30
31 namespace detail{
32
33 /* model for function_collection */
34
35 template<typename Signature>
36 struct function_model;
37
38 /* is_terminal defined out-class to allow for partial specialization */
39
40 template<typename T>
41 struct function_model_is_terminal:std::true_type{};
42
43 template<typename Signature>
44 struct function_model_is_terminal<callable_wrapper<Signature>>:
45 std::false_type{};
46
47 template<typename R,typename... Args>
48 struct function_model<R(Args...)>
49 {
50 using value_type=callable_wrapper<R(Args...)>;
51
52 template<typename Callable>
53 using is_implementation=is_invocable_r<R,Callable&,Args...>;
54
55 template<typename T>
56 using is_terminal=function_model_is_terminal<T>;
57
58 template<typename T>
59 static const std::type_info& subtypeid(const T&){return typeid(T);}
60
61 template<typename Signature>
62 static const std::type_info& subtypeid(
63 const callable_wrapper<Signature>& f)
64 {
65 return f.target_type();
66 }
67
68 template<typename T>
69 static void* subaddress(T& x){return boost::addressof(x);}
70
71 template<typename T>
72 static const void* subaddress(const T& x){return boost::addressof(x);}
73
74 template<typename Signature>
75 static void* subaddress(callable_wrapper<Signature>& f)
76 {
77 return f.data();
78 }
79
80 template<typename Signature>
81 static const void* subaddress(const callable_wrapper<Signature>& f)
82 {
83 return f.data();
84 }
85
86 using base_iterator=callable_wrapper_iterator<value_type>;
87 using const_base_iterator=callable_wrapper_iterator<const value_type>;
88 using base_sentinel=value_type*;
89 using const_base_sentinel=const value_type*;
90 template<typename Callable>
91 using iterator=Callable*;
92 template<typename Callable>
93 using const_iterator=const Callable*;
94 using segment_backend=detail::segment_backend<function_model>;
95 template<typename Callable,typename Allocator>
96 using segment_backend_implementation=split_segment<
97 function_model,
98 Callable,
99 typename std::allocator_traits<Allocator>::
100 template rebind_alloc<Callable>
101 >;
102 using segment_backend_unique_ptr=
103 typename segment_backend::segment_backend_unique_ptr;
104
105 static base_iterator nonconst_iterator(const_base_iterator it)
106 {
107 return base_iterator{
108 const_cast<value_type*>(static_cast<const value_type*>(it))};
109 }
110
111 template<typename T>
112 static iterator<T> nonconst_iterator(const_iterator<T> it)
113 {
114 return const_cast<iterator<T>>(it);
115 }
116
117 template<typename Callable,typename Allocator>
118 static segment_backend_unique_ptr make(const Allocator& al)
119 {
120 return segment_backend_implementation<Callable,Allocator>::new_(al,al);
121 }
122
123 private:
124 template<typename,typename,typename>
125 friend class split_segment;
126
127 template<typename Callable>
128 static value_type make_value_type(Callable& x){return value_type{x};}
129 };
130
131 } /* namespace poly_collection::detail */
132
133 } /* namespace poly_collection */
134
135 } /* namespace boost */
136
137 #endif