1 // Boost.TypeErasure library
3 // Copyright 2011 Steven Watanabe
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)
11 #if !defined(BOOST_PP_IS_ITERATING)
13 #ifndef BOOST_TYPE_ERASURE_CHECK_MATCH_HPP_INCLUDED
14 #define BOOST_TYPE_ERASURE_CHECK_MATCH_HPP_INCLUDED
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>
34 namespace type_erasure {
39 template<class Concept>
44 template<class P, class T, class Table>
45 bool maybe_check_table(const T& arg, const Table*& table, boost::mpl::true_)
48 table = &::boost::type_erasure::detail::access::table(arg);
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> >()();
57 template<class P, class T, class Table>
58 bool maybe_check_table(const T&, const Table*&, boost::mpl::false_)
63 template<class Concept, class T>
66 ::boost::type_erasure::is_placeholder<T>,
67 ::boost::type_erasure::is_relaxed<Concept>
73 #ifdef BOOST_TYPE_ERASURE_DOXYGEN
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.
82 template<class Concept, class Op, class... U>
83 bool check_match(const binding<Concept>& binding_arg, const Op& f, U&&... args);
88 template<class Op, class... U>
89 bool check_match(const Op& f, U&&... args);
93 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
97 template<class Concept>
98 bool check_table(const ::boost::type_erasure::binding<Concept>* t, void(*)())
103 template<class Concept, class R, class T0, class... T, class U0, class... U>
105 const ::boost::type_erasure::binding<Concept>* t,
110 typedef typename ::boost::remove_cv<
111 typename ::boost::remove_reference<T0>::type
113 if(!::boost::type_erasure::detail::maybe_check_table<t0>(
116 ::boost::type_erasure::detail::should_check<Concept, t0>()))
119 return check_table(t, static_cast<void(*)(T...)>(0), arg...);
124 template<class Concept, class Op, class... U>
126 const ::boost::type_erasure::binding<Concept>& table,
131 return ::boost::type_erasure::detail::check_table(
133 static_cast<typename ::boost::type_erasure::detail::get_signature<Op>::type*>(0),
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;
149 return ::boost::type_erasure::detail::check_table(
150 p, static_cast<typename ::boost::type_erasure::detail::get_signature<Op>::type*>(0), arg...);
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()
172 #define N BOOST_PP_ITERATION()
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), \
181 ::boost::type_erasure::detail::should_check<Concept, BOOST_PP_CAT(t, n)>())) \
187 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
188 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)>
190 BOOST_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))
195 BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_CHECK_TABLE, ~)
201 template<class Sig BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)>
202 struct BOOST_PP_CAT(do_extract_concept, N);
206 BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
207 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
209 struct BOOST_PP_CAT(do_extract_concept, N)<
210 R(BOOST_PP_ENUM_PARAMS(N, T))
211 BOOST_PP_ENUM_TRAILING_PARAMS(N, U)
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)>
222 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
231 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
234 const ::boost::type_erasure::binding<Concept>& table,
236 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
239 return ::boost::type_erasure::detail::BOOST_PP_CAT(check_table, N)(
241 (typename ::boost::type_erasure::detail::get_signature<Op>::type*)0
242 BOOST_PP_ENUM_TRAILING_PARAMS(N, arg));
249 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
253 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
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;
260 return ::boost::type_erasure::detail::BOOST_PP_CAT(check_table, N)(
262 (typename ::boost::type_erasure::detail::get_signature<Op>::type*)0
263 BOOST_PP_ENUM_TRAILING_PARAMS(N, arg));
267 #undef BOOST_TYPE_ERASURE_CHECK_TABLE