default.hpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file default.hpp
  3. /// Contains definition of the _default transform, which gives operators their
  4. /// usual C++ meanings and uses Boost.Typeof to deduce return types.
  5. //
  6. // Copyright 2008 Eric Niebler. Distributed under the Boost
  7. // Software License, Version 1.0. (See accompanying file
  8. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_PROTO_TRANSFORM_DEFAULT_HPP_EAN_04_04_2008
  10. #define BOOST_PROTO_TRANSFORM_DEFAULT_HPP_EAN_04_04_2008
  11. #include <boost/preprocessor/iteration/iterate.hpp>
  12. #include <boost/preprocessor/repetition/repeat.hpp>
  13. #include <boost/preprocessor/arithmetic/add.hpp>
  14. #include <boost/preprocessor/arithmetic/sub.hpp>
  15. #include <boost/preprocessor/repetition/enum.hpp>
  16. #include <boost/preprocessor/repetition/enum_shifted.hpp>
  17. #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
  18. #include <boost/ref.hpp>
  19. #include <boost/get_pointer.hpp>
  20. #include <boost/utility/enable_if.hpp>
  21. #include <boost/type_traits/is_member_pointer.hpp>
  22. #include <boost/type_traits/is_member_object_pointer.hpp>
  23. #include <boost/type_traits/is_member_function_pointer.hpp>
  24. #include <boost/proto/proto_fwd.hpp>
  25. #include <boost/proto/traits.hpp>
  26. #include <boost/proto/transform/impl.hpp>
  27. #include <boost/proto/transform/arg.hpp>
  28. #include <boost/proto/detail/decltype.hpp>
  29. namespace boost { namespace proto
  30. {
  31. namespace detail
  32. {
  33. template<typename Grammar, typename Tag>
  34. struct default_case
  35. : not_<_>
  36. {};
  37. template<typename Grammar>
  38. struct default_case<Grammar, tag::terminal>
  39. : when<terminal<_>, _value>
  40. {};
  41. template<typename Grammar>
  42. struct default_cases
  43. {
  44. template<typename Tag>
  45. struct case_
  46. : default_case<Grammar, Tag>
  47. {};
  48. };
  49. #define BOOST_PROTO_UNARY_DEFAULT_EVAL(OP, TAG, MAKE) \
  50. template<typename Grammar> \
  51. struct BOOST_PP_CAT(default_, TAG) \
  52. : transform<BOOST_PP_CAT(default_, TAG)<Grammar> > \
  53. { \
  54. template<typename Expr, typename State, typename Data> \
  55. struct impl \
  56. : transform_impl<Expr, State, Data> \
  57. { \
  58. private: \
  59. typedef typename result_of::child_c<Expr, 0>::type e0; \
  60. typedef typename Grammar::template impl<e0, State, Data>::result_type r0; \
  61. public: \
  62. BOOST_PROTO_DECLTYPE_(OP proto::detail::MAKE<r0>(), result_type) \
  63. result_type operator ()( \
  64. typename impl::expr_param e \
  65. , typename impl::state_param s \
  66. , typename impl::data_param d \
  67. ) const \
  68. { \
  69. typename Grammar::template impl<e0, State, Data> t0; \
  70. return OP t0(proto::child_c<0>(e), s, d); \
  71. } \
  72. }; \
  73. }; \
  74. \
  75. template<typename Grammar> \
  76. struct default_case<Grammar, tag::TAG> \
  77. : when<unary_expr<tag::TAG, Grammar>, BOOST_PP_CAT(default_, TAG)<Grammar> > \
  78. {}; \
  79. /**/
  80. #define BOOST_PROTO_BINARY_DEFAULT_EVAL(OP, TAG, LMAKE, RMAKE) \
  81. template<typename Grammar> \
  82. struct BOOST_PP_CAT(default_, TAG) \
  83. : transform<BOOST_PP_CAT(default_, TAG)<Grammar> > \
  84. { \
  85. template<typename Expr, typename State, typename Data> \
  86. struct impl \
  87. : transform_impl<Expr, State, Data> \
  88. { \
  89. private: \
  90. typedef typename result_of::child_c<Expr, 0>::type e0; \
  91. typedef typename result_of::child_c<Expr, 1>::type e1; \
  92. typedef typename Grammar::template impl<e0, State, Data>::result_type r0; \
  93. typedef typename Grammar::template impl<e1, State, Data>::result_type r1; \
  94. public: \
  95. BOOST_PROTO_DECLTYPE_( \
  96. proto::detail::LMAKE<r0>() OP proto::detail::RMAKE<r1>() \
  97. , result_type \
  98. ) \
  99. result_type operator ()( \
  100. typename impl::expr_param e \
  101. , typename impl::state_param s \
  102. , typename impl::data_param d \
  103. ) const \
  104. { \
  105. typename Grammar::template impl<e0, State, Data> t0; \
  106. typename Grammar::template impl<e1, State, Data> t1; \
  107. return t0(proto::child_c<0>(e), s, d) \
  108. OP t1(proto::child_c<1>(e), s, d); \
  109. } \
  110. }; \
  111. }; \
  112. \
  113. template<typename Grammar> \
  114. struct default_case<Grammar, tag::TAG> \
  115. : when<binary_expr<tag::TAG, Grammar, Grammar>, BOOST_PP_CAT(default_, TAG)<Grammar> > \
  116. {}; \
  117. /**/
  118. BOOST_PROTO_UNARY_DEFAULT_EVAL(+, unary_plus, make)
  119. BOOST_PROTO_UNARY_DEFAULT_EVAL(-, negate, make)
  120. BOOST_PROTO_UNARY_DEFAULT_EVAL(*, dereference, make)
  121. BOOST_PROTO_UNARY_DEFAULT_EVAL(~, complement, make)
  122. BOOST_PROTO_UNARY_DEFAULT_EVAL(&, address_of, make)
  123. BOOST_PROTO_UNARY_DEFAULT_EVAL(!, logical_not, make)
  124. BOOST_PROTO_UNARY_DEFAULT_EVAL(++, pre_inc, make_mutable)
  125. BOOST_PROTO_UNARY_DEFAULT_EVAL(--, pre_dec, make_mutable)
  126. BOOST_PROTO_BINARY_DEFAULT_EVAL(<<, shift_left, make_mutable, make)
  127. BOOST_PROTO_BINARY_DEFAULT_EVAL(>>, shift_right, make_mutable, make_mutable)
  128. BOOST_PROTO_BINARY_DEFAULT_EVAL(*, multiplies, make, make)
  129. BOOST_PROTO_BINARY_DEFAULT_EVAL(/, divides, make, make)
  130. BOOST_PROTO_BINARY_DEFAULT_EVAL(%, modulus, make, make)
  131. BOOST_PROTO_BINARY_DEFAULT_EVAL(+, plus, make, make)
  132. BOOST_PROTO_BINARY_DEFAULT_EVAL(-, minus, make, make)
  133. BOOST_PROTO_BINARY_DEFAULT_EVAL(<, less, make, make)
  134. BOOST_PROTO_BINARY_DEFAULT_EVAL(>, greater, make, make)
  135. BOOST_PROTO_BINARY_DEFAULT_EVAL(<=, less_equal, make, make)
  136. BOOST_PROTO_BINARY_DEFAULT_EVAL(>=, greater_equal, make, make)
  137. BOOST_PROTO_BINARY_DEFAULT_EVAL(==, equal_to, make, make)
  138. BOOST_PROTO_BINARY_DEFAULT_EVAL(!=, not_equal_to, make, make)
  139. BOOST_PROTO_BINARY_DEFAULT_EVAL(||, logical_or, make, make)
  140. BOOST_PROTO_BINARY_DEFAULT_EVAL(&&, logical_and, make, make)
  141. BOOST_PROTO_BINARY_DEFAULT_EVAL(&, bitwise_and, make, make)
  142. BOOST_PROTO_BINARY_DEFAULT_EVAL(|, bitwise_or, make, make)
  143. BOOST_PROTO_BINARY_DEFAULT_EVAL(^, bitwise_xor, make, make)
  144. BOOST_PROTO_BINARY_DEFAULT_EVAL(=, assign, make_mutable, make)
  145. BOOST_PROTO_BINARY_DEFAULT_EVAL(<<=, shift_left_assign, make_mutable, make)
  146. BOOST_PROTO_BINARY_DEFAULT_EVAL(>>=, shift_right_assign, make_mutable, make)
  147. BOOST_PROTO_BINARY_DEFAULT_EVAL(*=, multiplies_assign, make_mutable, make)
  148. BOOST_PROTO_BINARY_DEFAULT_EVAL(/=, divides_assign, make_mutable, make)
  149. BOOST_PROTO_BINARY_DEFAULT_EVAL(%=, modulus_assign, make_mutable, make)
  150. BOOST_PROTO_BINARY_DEFAULT_EVAL(+=, plus_assign, make_mutable, make)
  151. BOOST_PROTO_BINARY_DEFAULT_EVAL(-=, minus_assign, make_mutable, make)
  152. BOOST_PROTO_BINARY_DEFAULT_EVAL(&=, bitwise_and_assign, make_mutable, make)
  153. BOOST_PROTO_BINARY_DEFAULT_EVAL(|=, bitwise_or_assign, make_mutable, make)
  154. BOOST_PROTO_BINARY_DEFAULT_EVAL(^=, bitwise_xor_assign, make_mutable, make)
  155. #undef BOOST_PROTO_UNARY_DEFAULT_EVAL
  156. #undef BOOST_PROTO_BINARY_DEFAULT_EVAL
  157. /// INTERNAL ONLY
  158. template<typename Grammar, typename Expr, typename State, typename Data>
  159. struct is_member_function_invocation
  160. : is_member_function_pointer<
  161. typename uncvref<
  162. typename Grammar::template impl<
  163. typename result_of::child_c<Expr, 1>::type
  164. , State
  165. , Data
  166. >::result_type
  167. >::type
  168. >
  169. {};
  170. /// INTERNAL ONLY
  171. template<typename Grammar, typename Expr, typename State, typename Data, bool IsMemFunCall>
  172. struct default_mem_ptr_impl
  173. : transform_impl<Expr, State, Data>
  174. {
  175. private:
  176. typedef typename result_of::child_c<Expr, 0>::type e0;
  177. typedef typename result_of::child_c<Expr, 1>::type e1;
  178. typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
  179. typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
  180. public:
  181. typedef typename detail::mem_ptr_fun<r0, r1>::result_type result_type;
  182. result_type operator ()(
  183. typename default_mem_ptr_impl::expr_param e
  184. , typename default_mem_ptr_impl::state_param s
  185. , typename default_mem_ptr_impl::data_param d
  186. ) const
  187. {
  188. typename Grammar::template impl<e0, State, Data> t0;
  189. typename Grammar::template impl<e1, State, Data> t1;
  190. return detail::mem_ptr_fun<r0, r1>()(
  191. t0(proto::child_c<0>(e), s, d)
  192. , t1(proto::child_c<1>(e), s, d)
  193. );
  194. }
  195. };
  196. /// INTERNAL ONLY
  197. template<typename Grammar, typename Expr, typename State, typename Data>
  198. struct default_mem_ptr_impl<Grammar, Expr, State, Data, true>
  199. : transform_impl<Expr, State, Data>
  200. {
  201. private:
  202. typedef typename result_of::child_c<Expr, 0>::type e0;
  203. typedef typename result_of::child_c<Expr, 1>::type e1;
  204. typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
  205. typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
  206. public:
  207. typedef detail::memfun<r0, r1> result_type;
  208. result_type const operator ()(
  209. typename default_mem_ptr_impl::expr_param e
  210. , typename default_mem_ptr_impl::state_param s
  211. , typename default_mem_ptr_impl::data_param d
  212. ) const
  213. {
  214. typename Grammar::template impl<e0, State, Data> t0;
  215. typename Grammar::template impl<e1, State, Data> t1;
  216. return detail::memfun<r0, r1>(
  217. t0(proto::child_c<0>(e), s, d)
  218. , t1(proto::child_c<1>(e), s, d)
  219. );
  220. }
  221. };
  222. template<typename Grammar>
  223. struct default_mem_ptr
  224. : transform<default_mem_ptr<Grammar> >
  225. {
  226. template<typename Expr, typename State, typename Data>
  227. struct impl
  228. : default_mem_ptr_impl<
  229. Grammar
  230. , Expr
  231. , State
  232. , Data
  233. , is_member_function_invocation<Grammar, Expr, State, Data>::value
  234. >
  235. {};
  236. };
  237. template<typename Grammar>
  238. struct default_case<Grammar, tag::mem_ptr>
  239. : when<mem_ptr<Grammar, Grammar>, default_mem_ptr<Grammar> >
  240. {};
  241. template<typename Grammar>
  242. struct default_post_inc
  243. : transform<default_post_inc<Grammar> >
  244. {
  245. template<typename Expr, typename State, typename Data>
  246. struct impl
  247. : transform_impl<Expr, State, Data>
  248. {
  249. private:
  250. typedef typename result_of::child_c<Expr, 0>::type e0;
  251. typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
  252. public:
  253. BOOST_PROTO_DECLTYPE_(proto::detail::make_mutable<r0>() ++, result_type)
  254. result_type operator ()(
  255. typename impl::expr_param e
  256. , typename impl::state_param s
  257. , typename impl::data_param d
  258. ) const
  259. {
  260. typename Grammar::template impl<e0, State, Data> t0;
  261. return t0(proto::child_c<0>(e), s, d) ++;
  262. }
  263. };
  264. };
  265. template<typename Grammar>
  266. struct default_case<Grammar, tag::post_inc>
  267. : when<post_inc<Grammar>, default_post_inc<Grammar> >
  268. {};
  269. template<typename Grammar>
  270. struct default_post_dec
  271. : transform<default_post_dec<Grammar> >
  272. {
  273. template<typename Expr, typename State, typename Data>
  274. struct impl
  275. : transform_impl<Expr, State, Data>
  276. {
  277. private:
  278. typedef typename result_of::child_c<Expr, 0>::type e0;
  279. typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
  280. public:
  281. BOOST_PROTO_DECLTYPE_(proto::detail::make_mutable<r0>() --, result_type)
  282. result_type operator ()(
  283. typename impl::expr_param e
  284. , typename impl::state_param s
  285. , typename impl::data_param d
  286. ) const
  287. {
  288. typename Grammar::template impl<e0, State, Data> t0;
  289. return t0(proto::child_c<0>(e), s, d) --;
  290. }
  291. };
  292. };
  293. template<typename Grammar>
  294. struct default_case<Grammar, tag::post_dec>
  295. : when<post_dec<Grammar>, default_post_dec<Grammar> >
  296. {};
  297. template<typename Grammar>
  298. struct default_subscript
  299. : transform<default_subscript<Grammar> >
  300. {
  301. template<typename Expr, typename State, typename Data>
  302. struct impl
  303. : transform_impl<Expr, State, Data>
  304. {
  305. private:
  306. typedef typename result_of::child_c<Expr, 0>::type e0;
  307. typedef typename result_of::child_c<Expr, 1>::type e1;
  308. typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
  309. typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
  310. public:
  311. BOOST_PROTO_DECLTYPE_(
  312. proto::detail::make_subscriptable<r0>() [ proto::detail::make<r1>() ]
  313. , result_type
  314. )
  315. result_type operator ()(
  316. typename impl::expr_param e
  317. , typename impl::state_param s
  318. , typename impl::data_param d
  319. ) const
  320. {
  321. typename Grammar::template impl<e0, State, Data> t0;
  322. typename Grammar::template impl<e1, State, Data> t1;
  323. return t0(proto::child_c<0>(e), s, d) [
  324. t1(proto::child_c<1>(e), s, d) ];
  325. }
  326. };
  327. };
  328. template<typename Grammar>
  329. struct default_case<Grammar, tag::subscript>
  330. : when<subscript<Grammar, Grammar>, default_subscript<Grammar> >
  331. {};
  332. template<typename Grammar>
  333. struct default_if_else_
  334. {
  335. template<typename Expr, typename State, typename Data>
  336. struct impl
  337. : transform_impl<Expr, State, Data>
  338. {
  339. private:
  340. typedef typename result_of::child_c<Expr, 0>::type e0;
  341. typedef typename result_of::child_c<Expr, 1>::type e1;
  342. typedef typename result_of::child_c<Expr, 2>::type e2;
  343. typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
  344. typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
  345. typedef typename Grammar::template impl<e2, State, Data>::result_type r2;
  346. public:
  347. BOOST_PROTO_DECLTYPE_(
  348. proto::detail::make<r0>()
  349. ? proto::detail::make<r1>()
  350. : proto::detail::make<r2>()
  351. , result_type
  352. )
  353. result_type operator ()(
  354. typename impl::expr_param e
  355. , typename impl::state_param s
  356. , typename impl::data_param d
  357. ) const
  358. {
  359. typename Grammar::template impl<e0, State, Data> t0;
  360. typename Grammar::template impl<e1, State, Data> t1;
  361. typename Grammar::template impl<e2, State, Data> t2;
  362. return t0(proto::child_c<0>(e), s, d)
  363. ? t1(proto::child_c<1>(e), s, d)
  364. : t2(proto::child_c<2>(e), s, d);
  365. }
  366. };
  367. };
  368. template<typename Grammar>
  369. struct default_case<Grammar, tag::if_else_>
  370. : when<if_else_<Grammar, Grammar, Grammar>, default_if_else_<Grammar> >
  371. {};
  372. template<typename Grammar>
  373. struct default_comma
  374. : transform<default_comma<Grammar> >
  375. {
  376. template<typename Expr, typename State, typename Data>
  377. struct impl
  378. : transform_impl<Expr, State, Data>
  379. {
  380. private:
  381. typedef typename result_of::child_c<Expr, 0>::type e0;
  382. typedef typename result_of::child_c<Expr, 1>::type e1;
  383. typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
  384. typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
  385. public:
  386. typedef typename proto::detail::comma_result<r0, r1>::type result_type;
  387. result_type operator ()(
  388. typename impl::expr_param e
  389. , typename impl::state_param s
  390. , typename impl::data_param d
  391. ) const
  392. {
  393. typename Grammar::template impl<e0, State, Data> t0;
  394. typename Grammar::template impl<e1, State, Data> t1;
  395. return t0(proto::child_c<0>(e), s, d)
  396. , t1(proto::child_c<1>(e), s, d);
  397. }
  398. };
  399. };
  400. template<typename Grammar>
  401. struct default_case<Grammar, tag::comma>
  402. : when<comma<Grammar, Grammar>, default_comma<Grammar> >
  403. {};
  404. template<typename Grammar, typename Expr, typename State, typename Data, long Arity>
  405. struct default_function_impl;
  406. template<typename Grammar>
  407. struct default_function
  408. : transform<default_function<Grammar> >
  409. {
  410. template<typename Expr, typename State, typename Data>
  411. struct impl
  412. : default_function_impl<
  413. Grammar
  414. , Expr
  415. , State
  416. , Data
  417. , transform_impl<Expr, State, Data>::expr::proto_arity_c
  418. >
  419. {};
  420. };
  421. template<typename Grammar>
  422. struct default_case<Grammar, tag::function>
  423. : when<function<Grammar, vararg<Grammar> >, default_function<Grammar> >
  424. {};
  425. #define BOOST_PROTO_DEFAULT_EVAL_TYPE(Z, N, DATA) \
  426. typedef \
  427. typename result_of::child_c<DATA, N>::type \
  428. BOOST_PP_CAT(e, N); \
  429. \
  430. typedef \
  431. typename Grammar::template impl<BOOST_PP_CAT(e, N), State, Data>::result_type \
  432. BOOST_PP_CAT(r, N); \
  433. /**/
  434. #define BOOST_PROTO_DEFAULT_EVAL(Z, N, DATA) \
  435. typename Grammar::template impl<BOOST_PP_CAT(e, N), State, Data>()( \
  436. proto::child_c<N>(DATA), s, d \
  437. ) \
  438. /**/
  439. template<typename Grammar, typename Expr, typename State, typename Data>
  440. struct default_function_impl<Grammar, Expr, State, Data, 1>
  441. : transform_impl<Expr, State, Data>
  442. {
  443. BOOST_PROTO_DEFAULT_EVAL_TYPE(~, 0, Expr)
  444. typedef
  445. typename proto::detail::result_of_fixup<r0>::type
  446. function_type;
  447. typedef
  448. typename BOOST_PROTO_RESULT_OF<function_type()>::type
  449. result_type;
  450. result_type operator ()(
  451. typename default_function_impl::expr_param e
  452. , typename default_function_impl::state_param s
  453. , typename default_function_impl::data_param d
  454. ) const
  455. {
  456. return BOOST_PROTO_DEFAULT_EVAL(~, 0, e)();
  457. }
  458. };
  459. template<typename Grammar, typename Expr, typename State, typename Data>
  460. struct default_function_impl<Grammar, Expr, State, Data, 2>
  461. : transform_impl<Expr, State, Data>
  462. {
  463. BOOST_PROTO_DEFAULT_EVAL_TYPE(~, 0, Expr)
  464. BOOST_PROTO_DEFAULT_EVAL_TYPE(~, 1, Expr)
  465. typedef
  466. typename proto::detail::result_of_fixup<r0>::type
  467. function_type;
  468. typedef
  469. typename detail::result_of_<function_type(r1)>::type
  470. result_type;
  471. result_type operator ()(
  472. typename default_function_impl::expr_param e
  473. , typename default_function_impl::state_param s
  474. , typename default_function_impl::data_param d
  475. ) const
  476. {
  477. return this->invoke(
  478. e
  479. , s
  480. , d
  481. , is_member_function_pointer<function_type>()
  482. , is_member_object_pointer<function_type>()
  483. );
  484. }
  485. private:
  486. result_type invoke(
  487. typename default_function_impl::expr_param e
  488. , typename default_function_impl::state_param s
  489. , typename default_function_impl::data_param d
  490. , mpl::false_
  491. , mpl::false_
  492. ) const
  493. {
  494. return BOOST_PROTO_DEFAULT_EVAL(~, 0, e)(BOOST_PROTO_DEFAULT_EVAL(~, 1, e));
  495. }
  496. result_type invoke(
  497. typename default_function_impl::expr_param e
  498. , typename default_function_impl::state_param s
  499. , typename default_function_impl::data_param d
  500. , mpl::true_
  501. , mpl::false_
  502. ) const
  503. {
  504. BOOST_PROTO_USE_GET_POINTER();
  505. typedef typename detail::class_member_traits<function_type>::class_type class_type;
  506. return (
  507. BOOST_PROTO_GET_POINTER(class_type, (BOOST_PROTO_DEFAULT_EVAL(~, 1, e))) ->*
  508. BOOST_PROTO_DEFAULT_EVAL(~, 0, e)
  509. )();
  510. }
  511. result_type invoke(
  512. typename default_function_impl::expr_param e
  513. , typename default_function_impl::state_param s
  514. , typename default_function_impl::data_param d
  515. , mpl::false_
  516. , mpl::true_
  517. ) const
  518. {
  519. BOOST_PROTO_USE_GET_POINTER();
  520. typedef typename detail::class_member_traits<function_type>::class_type class_type;
  521. return (
  522. BOOST_PROTO_GET_POINTER(class_type, (BOOST_PROTO_DEFAULT_EVAL(~, 1, e))) ->*
  523. BOOST_PROTO_DEFAULT_EVAL(~, 0, e)
  524. );
  525. }
  526. };
  527. #include <boost/proto/transform/detail/default_function_impl.hpp>
  528. #undef BOOST_PROTO_DEFAULT_EVAL_TYPE
  529. #undef BOOST_PROTO_DEFAULT_EVAL
  530. }
  531. template<typename Grammar /*= detail::_default*/>
  532. struct _default
  533. : switch_<detail::default_cases<Grammar> >
  534. {};
  535. template<typename Grammar>
  536. struct is_callable<_default<Grammar> >
  537. : mpl::true_
  538. {};
  539. namespace detail
  540. {
  541. // Loopy indirection that allows proto::_default<> to be
  542. // used without specifying a Grammar argument.
  543. struct _default
  544. : proto::_default<>
  545. {};
  546. }
  547. }}
  548. #endif