call.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. #if !defined(BOOST_PP_IS_ITERATING)
  11. #ifndef BOOST_TYPE_ERASURE_CALL_HPP_INCLUDED
  12. #define BOOST_TYPE_ERASURE_CALL_HPP_INCLUDED
  13. #include <boost/assert.hpp>
  14. #include <boost/mpl/bool.hpp>
  15. #include <boost/mpl/eval_if.hpp>
  16. #include <boost/mpl/identity.hpp>
  17. #include <boost/type_traits/remove_cv.hpp>
  18. #include <boost/type_traits/remove_reference.hpp>
  19. #include <boost/preprocessor/cat.hpp>
  20. #include <boost/preprocessor/inc.hpp>
  21. #include <boost/preprocessor/iteration/iterate.hpp>
  22. #include <boost/preprocessor/repetition/repeat.hpp>
  23. #include <boost/preprocessor/repetition/enum.hpp>
  24. #include <boost/preprocessor/repetition/enum_trailing.hpp>
  25. #include <boost/preprocessor/repetition/enum_params.hpp>
  26. #include <boost/preprocessor/repetition/enum_binary_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/access.hpp>
  30. #include <boost/type_erasure/detail/adapt_to_vtable.hpp>
  31. #include <boost/type_erasure/detail/extract_concept.hpp>
  32. #include <boost/type_erasure/detail/get_signature.hpp>
  33. #include <boost/type_erasure/detail/check_call.hpp>
  34. #include <boost/type_erasure/is_placeholder.hpp>
  35. #include <boost/type_erasure/concept_of.hpp>
  36. #include <boost/type_erasure/config.hpp>
  37. #include <boost/type_erasure/require_match.hpp>
  38. namespace boost {
  39. namespace type_erasure {
  40. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  41. template<class Concept, class Placeholder>
  42. class any;
  43. template<class Concept>
  44. class binding;
  45. #endif
  46. namespace detail {
  47. template<class T>
  48. struct is_placeholder_arg :
  49. ::boost::type_erasure::is_placeholder<
  50. typename ::boost::remove_cv<
  51. typename ::boost::remove_reference<T>::type
  52. >::type
  53. >
  54. {};
  55. template<class T, class Table>
  56. int maybe_get_table(const T& arg, const Table*& table, boost::mpl::true_)
  57. {
  58. if(table == 0) {
  59. table = &::boost::type_erasure::detail::access::table(arg);
  60. }
  61. return 0;
  62. }
  63. template<class T, class Table>
  64. int maybe_get_table(const T&, const Table*&, boost::mpl::false_) { return 0; }
  65. template<class T>
  66. ::boost::type_erasure::detail::storage& convert_arg(any_base<T>& arg, boost::mpl::true_)
  67. {
  68. return ::boost::type_erasure::detail::access::data(arg);
  69. }
  70. template<class Concept, class T>
  71. const ::boost::type_erasure::detail::storage&
  72. convert_arg(any_base<any<Concept, const T&> >& arg, boost::mpl::true_)
  73. {
  74. return ::boost::type_erasure::detail::access::data(arg);
  75. }
  76. template<class T>
  77. const ::boost::type_erasure::detail::storage&
  78. convert_arg(const any_base<T>& arg, boost::mpl::true_)
  79. {
  80. return ::boost::type_erasure::detail::access::data(arg);
  81. }
  82. template<class Concept, class T>
  83. ::boost::type_erasure::detail::storage&
  84. convert_arg(const any_base<any<Concept, T&> >& arg, boost::mpl::true_)
  85. {
  86. return ::boost::type_erasure::detail::access::data(arg);
  87. }
  88. template<class Concept, class T>
  89. const ::boost::type_erasure::detail::storage&
  90. convert_arg(const any_base<any<Concept, const T&> >& arg, boost::mpl::true_)
  91. {
  92. return ::boost::type_erasure::detail::access::data(arg);
  93. }
  94. template<class Concept, class T>
  95. ::boost::type_erasure::detail::storage&
  96. convert_arg(param<Concept, T>& arg, boost::mpl::true_)
  97. {
  98. return ::boost::type_erasure::detail::access::data(arg);
  99. }
  100. template<class Concept, class T>
  101. const ::boost::type_erasure::detail::storage&
  102. convert_arg(param<Concept, const T&>& arg, boost::mpl::true_)
  103. {
  104. return ::boost::type_erasure::detail::access::data(arg);
  105. }
  106. template<class Concept, class T>
  107. const ::boost::type_erasure::detail::storage&
  108. convert_arg(const param<Concept, T>& arg, boost::mpl::true_)
  109. {
  110. return ::boost::type_erasure::detail::access::data(arg);
  111. }
  112. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  113. template<class Concept, class T>
  114. const ::boost::type_erasure::detail::storage&
  115. convert_arg(any_base<any<Concept, const T&> >&& arg, boost::mpl::true_)
  116. {
  117. return ::boost::type_erasure::detail::access::data(arg);
  118. }
  119. template<class Concept, class T>
  120. ::boost::type_erasure::detail::storage&
  121. convert_arg(any_base<any<Concept, T&> >&& arg, boost::mpl::true_)
  122. {
  123. return ::boost::type_erasure::detail::access::data(arg);
  124. }
  125. template<class Concept, class T>
  126. ::boost::type_erasure::detail::storage&&
  127. convert_arg(any_base<any<Concept, T> >&& arg, boost::mpl::true_)
  128. {
  129. return ::boost::type_erasure::detail::access::data(std::move(arg));
  130. }
  131. template<class Concept, class T>
  132. ::boost::type_erasure::detail::storage&&
  133. convert_arg(any_base<any<Concept, T&&> >& arg, boost::mpl::true_)
  134. {
  135. return ::boost::type_erasure::detail::access::data(arg);
  136. }
  137. template<class Concept, class T>
  138. ::boost::type_erasure::detail::storage&&
  139. convert_arg(const any_base<any<Concept, T&&> >& arg, boost::mpl::true_)
  140. {
  141. return ::boost::type_erasure::detail::access::data(arg);
  142. }
  143. template<class Concept, class T>
  144. const ::boost::type_erasure::detail::storage&
  145. convert_arg(param<Concept, const T&>&& arg, boost::mpl::true_)
  146. {
  147. return ::boost::type_erasure::detail::access::data(arg);
  148. }
  149. template<class Concept, class T>
  150. ::boost::type_erasure::detail::storage&
  151. convert_arg(param<Concept, T&>&& arg, boost::mpl::true_)
  152. {
  153. return ::boost::type_erasure::detail::access::data(arg);
  154. }
  155. template<class Concept, class T>
  156. ::boost::type_erasure::detail::storage&&
  157. convert_arg(param<Concept, T>&& arg, boost::mpl::true_)
  158. {
  159. return ::boost::type_erasure::detail::access::data(std::move(arg));
  160. }
  161. template<class Concept, class T>
  162. ::boost::type_erasure::detail::storage&&
  163. convert_arg(param<Concept, T&&>& arg, boost::mpl::true_)
  164. {
  165. return ::boost::type_erasure::detail::access::data(arg);
  166. }
  167. template<class Concept, class T>
  168. ::boost::type_erasure::detail::storage&&
  169. convert_arg(const param<Concept, T&&>& arg, boost::mpl::true_)
  170. {
  171. return ::boost::type_erasure::detail::access::data(arg);
  172. }
  173. template<class T>
  174. T&& convert_arg(T&& arg, boost::mpl::false_) { return std::forward<T>(arg); }
  175. #else
  176. template<class T>
  177. T& convert_arg(T& arg, boost::mpl::false_) { return arg; }
  178. #endif
  179. }
  180. #ifdef BOOST_TYPE_ERASURE_DOXYGEN
  181. /**
  182. * Dispatches a type erased function.
  183. *
  184. * @c Op must be a primitive concept which is present in
  185. * @c Concept. Its signature determines how the arguments of
  186. * \call are handled. If the argument is a @ref placeholder,
  187. * \call expects an @ref any using that @ref placeholder.
  188. * This @ref any is unwrapped by \call. The type that
  189. * it stores must be the same type specified by @c binding.
  190. * Any arguments that are not placeholders in the signature
  191. * of @c Op are passed through unchanged.
  192. *
  193. * If @c binding is not specified, it will be deduced from
  194. * the arguments. Naturally this requires at least one
  195. * argument to be an @ref any. In this case, all @ref any
  196. * arguments must have the same @ref binding.
  197. *
  198. * \return The result of the operation. If the result type
  199. * of the signature of @c Op is a placeholder, the
  200. * result will be converted to the appropriate @ref
  201. * any type.
  202. *
  203. * \throws bad_function_call if @ref relaxed is
  204. * in @c Concept and there is a type mismatch.
  205. *
  206. * Example:
  207. *
  208. * @code
  209. * typedef mpl::vector<
  210. * copy_constructible<_b>,
  211. * addable<_a, int, _b> > concept;
  212. * any<concept, _a> a = ...;
  213. * any<concept, _b> b(call(addable<_a, int, _b>(), a, 10));
  214. * @endcode
  215. *
  216. * The signature of @ref addable is <code>_b(const _a&, const int&)</code>
  217. */
  218. template<class Concept, class Op, class... U>
  219. typename ::boost::type_erasure::detail::call_impl<Sig, U..., Concept>::type
  220. call(const binding<Concept>& binding_arg, const Op&, U&&... args);
  221. /**
  222. * \overload
  223. */
  224. template<class Op, class... U>
  225. typename ::boost::type_erasure::detail::call_impl<Sig, U...>::type
  226. call(const Op&, U&&... args);
  227. #else
  228. namespace detail {
  229. template<class Sig, class Args, class Concept = void,
  230. bool Check = ::boost::type_erasure::detail::check_call<Sig, Args>::type::value>
  231. struct call_impl {};
  232. template<class Op, class Args, class Concept = void>
  233. struct call_result :
  234. call_impl<
  235. typename ::boost::type_erasure::detail::get_signature<Op>::type,
  236. Args,
  237. Concept>
  238. {};
  239. template<class C1, class Args, class Concept>
  240. struct call_result<
  241. ::boost::type_erasure::binding<C1>,
  242. Args,
  243. Concept
  244. >
  245. {};
  246. }
  247. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  248. namespace detail {
  249. template<class... T>
  250. void ignore(const T&...) {}
  251. #ifndef BOOST_TYPE_ERASURE_USE_MP11
  252. template<class R, class... T, class... U>
  253. const ::boost::type_erasure::binding<
  254. typename ::boost::type_erasure::detail::extract_concept<void(T...), U...>::type>*
  255. extract_table(R(*)(T...), const U&... arg)
  256. {
  257. const ::boost::type_erasure::binding<
  258. typename ::boost::type_erasure::detail::extract_concept<
  259. void(T...), U...>::type>* result = 0;
  260. // the order that we run maybe_get_table in doesn't matter
  261. ignore(::boost::type_erasure::detail::maybe_get_table(
  262. arg,
  263. result,
  264. ::boost::type_erasure::detail::is_placeholder_arg<T>())...);
  265. BOOST_ASSERT(result != 0);
  266. return result;
  267. }
  268. #else
  269. template<class R, class... T, class... U>
  270. const ::boost::type_erasure::binding<
  271. ::boost::type_erasure::detail::extract_concept_t< ::boost::mp11::mp_list<T...>, ::boost::mp11::mp_list<U...> > >*
  272. extract_table(R(*)(T...), const U&... arg)
  273. {
  274. const ::boost::type_erasure::binding<
  275. ::boost::type_erasure::detail::extract_concept_t<
  276. ::boost::mp11::mp_list<T...>, ::boost::mp11::mp_list<U...> > >* result = 0;
  277. // the order that we run maybe_get_table in doesn't matter
  278. ignore(::boost::type_erasure::detail::maybe_get_table(
  279. arg,
  280. result,
  281. ::boost::type_erasure::detail::is_placeholder_arg<T>())...);
  282. BOOST_ASSERT(result != 0);
  283. return result;
  284. }
  285. #endif
  286. template<class Sig, class Args, class Concept, bool ReturnsAny>
  287. struct call_impl_dispatch;
  288. template<class R, class... T, class... U, class Concept>
  289. struct call_impl_dispatch<R(T...), void(U...), Concept, false>
  290. {
  291. typedef R type;
  292. template<class F>
  293. static R apply(const ::boost::type_erasure::binding<Concept>* table, U... arg)
  294. {
  295. return table->template find<F>()(
  296. ::boost::type_erasure::detail::convert_arg(
  297. ::std::forward<U>(arg),
  298. ::boost::type_erasure::detail::is_placeholder_arg<T>())...);
  299. }
  300. };
  301. template<class R, class... T, class... U, class Concept>
  302. struct call_impl_dispatch<R(T...), void(U...), Concept, true>
  303. {
  304. typedef ::boost::type_erasure::any<Concept, R> type;
  305. template<class F>
  306. static type apply(const ::boost::type_erasure::binding<Concept>* table, U... arg)
  307. {
  308. return type(table->template find<F>()(
  309. ::boost::type_erasure::detail::convert_arg(
  310. ::std::forward<U>(arg),
  311. ::boost::type_erasure::detail::is_placeholder_arg<T>())...), *table);
  312. }
  313. };
  314. template<class R, class... T, class... U, class Concept>
  315. struct call_impl<R(T...), void(U...), Concept, true> :
  316. ::boost::type_erasure::detail::call_impl_dispatch<
  317. R(T...),
  318. void(U...),
  319. Concept,
  320. ::boost::type_erasure::detail::is_placeholder_arg<R>::value
  321. >
  322. {
  323. };
  324. #ifndef BOOST_TYPE_ERASURE_USE_MP11
  325. template<class R, class... T, class... U>
  326. struct call_impl<R(T...), void(U...), void, true> :
  327. ::boost::type_erasure::detail::call_impl_dispatch<
  328. R(T...),
  329. void(U...),
  330. typename ::boost::type_erasure::detail::extract_concept<
  331. void(T...),
  332. typename ::boost::remove_reference<U>::type...
  333. >::type,
  334. ::boost::type_erasure::detail::is_placeholder_arg<R>::value
  335. >
  336. {
  337. };
  338. #else
  339. template<class R, class... T, class... U>
  340. struct call_impl<R(T...), void(U...), void, true> :
  341. ::boost::type_erasure::detail::call_impl_dispatch<
  342. R(T...),
  343. void(U...),
  344. ::boost::type_erasure::detail::extract_concept_t<
  345. ::boost::mp11::mp_list<T...>,
  346. ::boost::mp11::mp_list< ::boost::remove_reference_t<U>...>
  347. >,
  348. ::boost::type_erasure::detail::is_placeholder_arg<R>::value
  349. >
  350. {
  351. };
  352. #endif
  353. }
  354. template<
  355. class Concept,
  356. class Op,
  357. class... U
  358. >
  359. typename ::boost::type_erasure::detail::call_result<
  360. Op,
  361. void(U&&...),
  362. Concept
  363. >::type
  364. unchecked_call(
  365. const ::boost::type_erasure::binding<Concept>& table,
  366. const Op&,
  367. U&&... arg)
  368. {
  369. return ::boost::type_erasure::detail::call_impl<
  370. typename ::boost::type_erasure::detail::get_signature<Op>::type,
  371. void(U&&...),
  372. Concept
  373. >::template apply<
  374. typename ::boost::type_erasure::detail::adapt_to_vtable<Op>::type
  375. >(&table, std::forward<U>(arg)...);
  376. }
  377. template<class Concept, class Op, class... U>
  378. typename ::boost::type_erasure::detail::call_result<
  379. Op,
  380. void(U&&...),
  381. Concept
  382. >::type
  383. call(
  384. const ::boost::type_erasure::binding<Concept>& table,
  385. const Op& f,
  386. U&&... arg)
  387. {
  388. ::boost::type_erasure::require_match(table, f, std::forward<U>(arg)...);
  389. return ::boost::type_erasure::unchecked_call(table, f, std::forward<U>(arg)...);
  390. }
  391. template<class Op, class... U>
  392. typename ::boost::type_erasure::detail::call_result<
  393. Op,
  394. void(U&&...)
  395. >::type
  396. unchecked_call(
  397. const Op&,
  398. U&&... arg)
  399. {
  400. return ::boost::type_erasure::detail::call_impl<
  401. typename ::boost::type_erasure::detail::get_signature<Op>::type,
  402. void(U&&...)
  403. >::template apply<
  404. typename ::boost::type_erasure::detail::adapt_to_vtable<Op>::type
  405. >(::boost::type_erasure::detail::extract_table(
  406. static_cast<typename ::boost::type_erasure::detail::get_signature<Op>::type*>(0), arg...),
  407. std::forward<U>(arg)...);
  408. }
  409. template<class Op, class... U>
  410. typename ::boost::type_erasure::detail::call_result<
  411. Op,
  412. void(U&&...)
  413. >::type
  414. call(
  415. const Op& f,
  416. U&&... arg)
  417. {
  418. ::boost::type_erasure::require_match(f, std::forward<U>(arg)...);
  419. return ::boost::type_erasure::unchecked_call(f, std::forward<U>(arg)...);
  420. }
  421. #else
  422. #define BOOST_PP_FILENAME_1 <boost/type_erasure/call.hpp>
  423. #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_ARITY)
  424. #include BOOST_PP_ITERATE()
  425. #endif
  426. #endif
  427. }
  428. }
  429. #endif
  430. #else
  431. #define N BOOST_PP_ITERATION()
  432. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  433. #define BOOST_TYPE_ERASURE_CONVERT_ARG(z, n, data) \
  434. ::boost::type_erasure::detail::convert_arg( \
  435. std::forward<BOOST_PP_CAT(U, n)>(BOOST_PP_CAT(arg, n)), \
  436. ::boost::type_erasure::detail::is_placeholder_arg<BOOST_PP_CAT(T, n)>())
  437. #else
  438. #define BOOST_TYPE_ERASURE_CONVERT_ARG(z, n, data) \
  439. ::boost::type_erasure::detail::convert_arg( \
  440. BOOST_PP_CAT(arg, n), \
  441. ::boost::type_erasure::detail::is_placeholder_arg<BOOST_PP_CAT(T, n)>())
  442. #endif
  443. #define BOOST_TYPE_ERASURE_GET_TABLE(z, n, data) \
  444. ::boost::type_erasure::detail::maybe_get_table( \
  445. BOOST_PP_CAT(arg, n), \
  446. result, \
  447. ::boost::type_erasure::detail::is_placeholder_arg<BOOST_PP_CAT(T, n)>());
  448. namespace detail {
  449. #if N != 0
  450. template<
  451. class R,
  452. BOOST_PP_ENUM_PARAMS(N, class T),
  453. BOOST_PP_ENUM_PARAMS(N, class U)>
  454. const ::boost::type_erasure::binding<
  455. typename ::boost::type_erasure::detail::BOOST_PP_CAT(extract_concept, N)<
  456. BOOST_PP_ENUM_PARAMS(N, T),
  457. BOOST_PP_ENUM_PARAMS(N, U)>::type>*
  458. BOOST_PP_CAT(extract_table, N)(R(*)(BOOST_PP_ENUM_PARAMS(N, T)), BOOST_PP_ENUM_BINARY_PARAMS(N, const U, &arg))
  459. {
  460. const ::boost::type_erasure::binding<
  461. typename ::boost::type_erasure::detail::BOOST_PP_CAT(extract_concept, N)<
  462. BOOST_PP_ENUM_PARAMS(N, T),
  463. BOOST_PP_ENUM_PARAMS(N, U)>::type>* result = 0;
  464. BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_GET_TABLE, ~)
  465. BOOST_ASSERT(result != 0);
  466. return result;
  467. }
  468. #endif
  469. template<
  470. class R
  471. BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
  472. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U),
  473. class Concept
  474. #if N != 0
  475. = typename ::boost::type_erasure::detail::BOOST_PP_CAT(extract_concept, N)<
  476. BOOST_PP_ENUM_PARAMS(N, T),
  477. BOOST_PP_ENUM_PARAMS(N, U)
  478. >::type
  479. #endif
  480. ,
  481. bool ReturnsAny = ::boost::type_erasure::detail::is_placeholder_arg<R>::value>
  482. struct BOOST_PP_CAT(call_impl, N);
  483. template<
  484. class R
  485. BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
  486. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U),
  487. class Concept
  488. >
  489. struct BOOST_PP_CAT(call_impl, N)<
  490. R
  491. BOOST_PP_ENUM_TRAILING_PARAMS(N, T)
  492. BOOST_PP_ENUM_TRAILING_PARAMS(N, U),
  493. Concept,
  494. false
  495. >
  496. {
  497. typedef R type;
  498. template<class F>
  499. static R apply(const ::boost::type_erasure::binding<Concept>* table
  500. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, arg))
  501. {
  502. return table->template find<F>()(
  503. BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_CONVERT_ARG, ~));
  504. }
  505. };
  506. template<
  507. class R
  508. BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
  509. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U),
  510. class Concept
  511. >
  512. struct BOOST_PP_CAT(call_impl, N)<
  513. R
  514. BOOST_PP_ENUM_TRAILING_PARAMS(N, T)
  515. BOOST_PP_ENUM_TRAILING_PARAMS(N, U),
  516. Concept,
  517. true
  518. >
  519. {
  520. typedef ::boost::type_erasure::any<Concept, R> type;
  521. template<class F>
  522. static type apply(const ::boost::type_erasure::binding<Concept>* table
  523. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, arg))
  524. {
  525. return type(table->template find<F>()(
  526. BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_CONVERT_ARG, ~)), *table);
  527. }
  528. };
  529. template<
  530. class R
  531. BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
  532. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U),
  533. class Concept
  534. >
  535. struct call_impl<R(BOOST_PP_ENUM_PARAMS(N, T)), void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, u)), Concept, true>
  536. : BOOST_PP_CAT(call_impl, N)<R BOOST_PP_ENUM_TRAILING_PARAMS(N, T) BOOST_PP_ENUM_TRAILING_PARAMS(N, U), Concept>
  537. {};
  538. #if N != 0
  539. template<
  540. class R
  541. BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)
  542. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
  543. >
  544. struct call_impl<R(BOOST_PP_ENUM_PARAMS(N, T)), void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, u)), void, true>
  545. : BOOST_PP_CAT(call_impl, N)<R BOOST_PP_ENUM_TRAILING_PARAMS(N, T) BOOST_PP_ENUM_TRAILING_PARAMS(N, U)>
  546. {};
  547. #endif
  548. }
  549. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  550. #define RREF &
  551. #define BOOST_TYPE_ERASURE_FORWARD_ARGS(N, X, x) BOOST_PP_ENUM_TRAILING_PARAMS(N, x)
  552. #else
  553. #define RREF &&
  554. #define BOOST_TYPE_ERASURE_FORWARD_ARGS_I(z, n, data) std::forward<BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n)>(BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, data), n))
  555. #define BOOST_TYPE_ERASURE_FORWARD_ARGS(N, X, x) BOOST_PP_ENUM_TRAILING(N, BOOST_TYPE_ERASURE_FORWARD_ARGS_I, (X, x))
  556. #endif
  557. template<
  558. class Concept,
  559. class Op
  560. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
  561. >
  562. typename ::boost::type_erasure::detail::call_result<
  563. Op,
  564. void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, RREF u)),
  565. Concept
  566. >::type
  567. unchecked_call(
  568. const ::boost::type_erasure::binding<Concept>& table,
  569. const Op&
  570. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
  571. {
  572. return ::boost::type_erasure::detail::call_impl<
  573. typename ::boost::type_erasure::detail::get_signature<Op>::type,
  574. void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, RREF u)),
  575. Concept
  576. >::template apply<
  577. typename ::boost::type_erasure::detail::adapt_to_vtable<Op>::type
  578. >(&table BOOST_TYPE_ERASURE_FORWARD_ARGS(N, U, arg));
  579. }
  580. template<
  581. class Concept,
  582. class Op
  583. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
  584. >
  585. typename ::boost::type_erasure::detail::call_result<
  586. Op,
  587. void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, RREF u)),
  588. Concept
  589. >::type
  590. call(
  591. const ::boost::type_erasure::binding<Concept>& table,
  592. const Op& f
  593. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
  594. {
  595. ::boost::type_erasure::require_match(table, f BOOST_TYPE_ERASURE_FORWARD_ARGS(N, U, arg));
  596. return ::boost::type_erasure::unchecked_call(table, f BOOST_TYPE_ERASURE_FORWARD_ARGS(N, U, arg));
  597. }
  598. #if N != 0
  599. template<
  600. class Op
  601. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
  602. >
  603. typename ::boost::type_erasure::detail::call_result<
  604. Op,
  605. void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, RREF u))
  606. >::type
  607. unchecked_call(
  608. const Op&
  609. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
  610. {
  611. return ::boost::type_erasure::detail::call_impl<
  612. typename ::boost::type_erasure::detail::get_signature<Op>::type,
  613. void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, RREF u))
  614. >::template apply<
  615. typename ::boost::type_erasure::detail::adapt_to_vtable<Op>::type
  616. >(
  617. ::boost::type_erasure::detail::BOOST_PP_CAT(extract_table, N)(
  618. (typename ::boost::type_erasure::detail::get_signature<Op>::type*)0,
  619. BOOST_PP_ENUM_PARAMS(N, arg))
  620. BOOST_TYPE_ERASURE_FORWARD_ARGS(N, U, arg)
  621. );
  622. }
  623. template<
  624. class Op
  625. BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)
  626. >
  627. typename ::boost::type_erasure::detail::call_result<
  628. Op,
  629. void(BOOST_PP_ENUM_BINARY_PARAMS(N, U, RREF u))
  630. >::type
  631. call(
  632. const Op& f
  633. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, RREF arg))
  634. {
  635. ::boost::type_erasure::require_match(f BOOST_TYPE_ERASURE_FORWARD_ARGS(N, U, arg));
  636. return ::boost::type_erasure::unchecked_call(f BOOST_TYPE_ERASURE_FORWARD_ARGS(N, U, arg));
  637. }
  638. #endif
  639. #undef RREF
  640. #undef BOOST_TYPE_ERASURE_FORWARD_ARGS
  641. #undef BOOST_TYPE_ERASURE_FORWARD_ARGS_I
  642. #undef BOOST_TYPE_ERASURE_GET_TABLE
  643. #undef BOOST_TYPE_ERASURE_CONVERT_ARG
  644. #undef N
  645. #endif