]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/type_erasure/check_match.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / type_erasure / check_match.hpp
CommitLineData
7c673cae
FG
1// Boost.TypeErasure library
2//
3// Copyright 2011 Steven Watanabe
4//
5// Distributed under the Boost Software License Version 1.0. (See
6// accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// $Id$
10
11#if !defined(BOOST_PP_IS_ITERATING)
12
13#ifndef BOOST_TYPE_ERASURE_CHECK_MATCH_HPP_INCLUDED
14#define BOOST_TYPE_ERASURE_CHECK_MATCH_HPP_INCLUDED
15
16#include <boost/mpl/vector.hpp>
17#include <boost/mpl/bool.hpp>
18#include <boost/mpl/is_sequence.hpp>
19#include <boost/mpl/find_if.hpp>
20#include <boost/mpl/not.hpp>
21#include <boost/mpl/end.hpp>
22#include <boost/type_traits/is_same.hpp>
23#include <boost/preprocessor/cat.hpp>
24#include <boost/preprocessor/iteration/iterate.hpp>
25#include <boost/preprocessor/repetition/repeat.hpp>
26#include <boost/preprocessor/repetition/enum_params.hpp>
27#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
28#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
29#include <boost/type_erasure/detail/extract_concept.hpp>
30#include <boost/type_erasure/relaxed.hpp>
31#include <boost/type_erasure/detail/access.hpp>
32
33namespace boost {
34namespace type_erasure {
35
36template<class T>
37struct typeid_;
38
39template<class Concept>
40class binding;
41
42namespace detail {
43
44template<class P, class T, class Table>
45bool maybe_check_table(const T& arg, const Table*& table, boost::mpl::true_)
46{
47 if(table == 0) {
48 table = &::boost::type_erasure::detail::access::table(arg);
49 return true;
50 } else {
51 return table->template find< ::boost::type_erasure::typeid_<P> >()() ==
52 ::boost::type_erasure::detail::access::table(arg).
53 template find< ::boost::type_erasure::typeid_<P> >()();
54 }
55}
56
57template<class P, class T, class Table>
58bool maybe_check_table(const T&, const Table*&, boost::mpl::false_)
59{
60 return true;
61}
62
63template<class Concept, class T>
64struct should_check :
65 boost::mpl::and_<
66 ::boost::type_erasure::is_placeholder<T>,
67 ::boost::type_erasure::is_relaxed<Concept>
68 >
69{};
70
71}
72
73#ifdef BOOST_TYPE_ERASURE_DOXYGEN
74
75/**
76 * If @ref relaxed is in @c Concept, checks whether the
77 * arguments to @c f match the types specified by
78 * @c binding. If @ref relaxed is not in @c Concept,
79 * returns true. If @c binding is not specified, it will
80 * be deduced from the arguments.
81 */
82template<class Concept, class Op, class... U>
83bool check_match(const binding<Concept>& binding_arg, const Op& f, U&&... args);
84
85/**
86 * \overload
87 */
88template<class Op, class... U>
89bool check_match(const Op& f, U&&... args);
90
91#else
92
93#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
94
95namespace detail {
96
97template<class Concept>
98bool check_table(const ::boost::type_erasure::binding<Concept>* t, void(*)())
99{
100 return true;
101}
102
103template<class Concept, class R, class T0, class... T, class U0, class... U>
104bool check_table(
105 const ::boost::type_erasure::binding<Concept>* t,
106 R(*)(T0, T...),
107 const U0& arg0,
108 const U&... arg)
109{
110 typedef typename ::boost::remove_cv<
111 typename ::boost::remove_reference<T0>::type
112 >::type t0;
113 if(!::boost::type_erasure::detail::maybe_check_table<t0>(
114 arg0,
115 t,
116 ::boost::type_erasure::detail::should_check<Concept, t0>()))
117 return false;
118
119 return check_table(t, static_cast<void(*)(T...)>(0), arg...);
120}
121
122}
123
124template<class Concept, class Op, class... U>
125bool check_match(
126 const ::boost::type_erasure::binding<Concept>& table,
127 const Op&,
128 U&&... arg)
129{
130
131 return ::boost::type_erasure::detail::check_table(
132 &table,
133 static_cast<typename ::boost::type_erasure::detail::get_signature<Op>::type*>(0),
134 arg...);
135}
136
137template<
138 class Op,
139 class... U
140>
141bool check_match(
142 const Op&,
143 U&&... arg)
144{
145 const ::boost::type_erasure::binding<
146 typename ::boost::type_erasure::detail::extract_concept<
147 typename ::boost::type_erasure::detail::get_signature<Op>::type, U...>::type>* p = 0;
148
149 return ::boost::type_erasure::detail::check_table(
150 p, static_cast<typename ::boost::type_erasure::detail::get_signature<Op>::type*>(0), arg...);
151}
152
153#else
154
155#define BOOST_PP_FILENAME_1 <boost/type_erasure/check_match.hpp>
156#define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_ARITY)
157#include BOOST_PP_ITERATE()
158
159#endif
160
161#endif
162
163}
164}
165
166#endif
167
168#else
169
170namespace detail {
171
172#define N BOOST_PP_ITERATION()
173
174#define BOOST_TYPE_ERASURE_CHECK_TABLE(z, n, data) \
175 typedef typename ::boost::remove_cv< \
176 typename ::boost::remove_reference<BOOST_PP_CAT(T, n)>::type \
177 >::type BOOST_PP_CAT(t, n); \
178 if(!::boost::type_erasure::detail::maybe_check_table<BOOST_PP_CAT(t, n)>( \
179 BOOST_PP_CAT(arg, n), \
180 t, \
181 ::boost::type_erasure::detail::should_check<Concept, BOOST_PP_CAT(t, n)>())) \
182 return false;
183
184template<
185 class Concept,
186 class R
187 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
188 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)>
189bool
190BOOST_PP_CAT(check_table, N)(
191 const ::boost::type_erasure::binding<Concept>* t,
192 R (*)(BOOST_PP_ENUM_PARAMS(N, T))
193 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, const U, &arg))
194{
195 BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_CHECK_TABLE, ~)
196 return true;
197}
198
199#if N != 0
200
201template<class Sig BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)>
202struct BOOST_PP_CAT(do_extract_concept, N);
203
204template<
205 class R
206 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
207 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
208>
209struct BOOST_PP_CAT(do_extract_concept, N)<
210 R(BOOST_PP_ENUM_PARAMS(N, T))
211 BOOST_PP_ENUM_TRAILING_PARAMS(N, U)
212>
213 : ::boost::type_erasure::detail::BOOST_PP_CAT(extract_concept, N)<
214 BOOST_PP_ENUM_PARAMS(N, T)
215 BOOST_PP_ENUM_TRAILING_PARAMS(N, U)>
216{};
217
218#endif
219
220}
221
222#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
223#define RREF &
224#else
225#define RREF &&
226#endif
227
228template<
229 class Concept,
230 class Op
231 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
232>
233bool check_match(
234 const ::boost::type_erasure::binding<Concept>& table,
235 const Op&
236 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
237{
238
239 return ::boost::type_erasure::detail::BOOST_PP_CAT(check_table, N)(
240 &table,
241 (typename ::boost::type_erasure::detail::get_signature<Op>::type*)0
242 BOOST_PP_ENUM_TRAILING_PARAMS(N, arg));
243}
244
245#if N != 0
246
247template<
248 class Op
249 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
250>
251bool check_match(
252 const Op&
253 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
254{
255 const ::boost::type_erasure::binding<
256 typename ::boost::type_erasure::detail::BOOST_PP_CAT(do_extract_concept, N)<
257 typename ::boost::type_erasure::detail::get_signature<Op>::type,
258 BOOST_PP_ENUM_PARAMS(N, U)>::type>* p = 0;
259
260 return ::boost::type_erasure::detail::BOOST_PP_CAT(check_table, N)(
261 p,
262 (typename ::boost::type_erasure::detail::get_signature<Op>::type*)0
263 BOOST_PP_ENUM_TRAILING_PARAMS(N, arg));
264}
265
266#undef RREF
267#undef BOOST_TYPE_ERASURE_CHECK_TABLE
268#undef N
269
270#endif
271
272#endif