member_ptr.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. // Boost Lambda Library -- member_ptr.hpp ---------------------
  2. // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  3. // Copyright (C) 2000 Gary Powell (gary.powell@sierra.com)
  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. // For more information, see www.boost.org
  10. // --------------------------------------------------------------------------
  11. #if !defined(BOOST_LAMBDA_MEMBER_PTR_HPP)
  12. #define BOOST_LAMBDA_MEMBER_PTR_HPP
  13. namespace boost {
  14. namespace lambda {
  15. class member_pointer_action {};
  16. namespace detail {
  17. // the boost type_traits member_pointer traits are not enough,
  18. // need to know more details.
  19. template<class T>
  20. struct member_pointer {
  21. typedef typename boost::add_reference<T>::type type;
  22. typedef detail::unspecified class_type;
  23. typedef detail::unspecified qualified_class_type;
  24. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  25. BOOST_STATIC_CONSTANT(bool, is_function_member = false);
  26. };
  27. template<class T, class U>
  28. struct member_pointer<T U::*> {
  29. typedef typename boost::add_reference<T>::type type;
  30. typedef U class_type;
  31. typedef U qualified_class_type;
  32. BOOST_STATIC_CONSTANT(bool, is_data_member = true);
  33. BOOST_STATIC_CONSTANT(bool, is_function_member = false);
  34. };
  35. template<class T, class U>
  36. struct member_pointer<const T U::*> {
  37. typedef typename boost::add_reference<const T>::type type;
  38. typedef U class_type;
  39. typedef const U qualified_class_type;
  40. BOOST_STATIC_CONSTANT(bool, is_data_member = true);
  41. BOOST_STATIC_CONSTANT(bool, is_function_member = false);
  42. };
  43. template<class T, class U>
  44. struct member_pointer<volatile T U::*> {
  45. typedef typename boost::add_reference<volatile T>::type type;
  46. typedef U class_type;
  47. typedef volatile U qualified_class_type;
  48. BOOST_STATIC_CONSTANT(bool, is_data_member = true);
  49. BOOST_STATIC_CONSTANT(bool, is_function_member = false);
  50. };
  51. template<class T, class U>
  52. struct member_pointer<const volatile T U::*> {
  53. typedef typename boost::add_reference<const volatile T>::type type;
  54. typedef U class_type;
  55. typedef const volatile U qualified_class_type;
  56. BOOST_STATIC_CONSTANT(bool, is_data_member = true);
  57. BOOST_STATIC_CONSTANT(bool, is_function_member = false);
  58. };
  59. // -- nonconst member functions --
  60. template<class T, class U>
  61. struct member_pointer<T (U::*)()> {
  62. typedef T type;
  63. typedef U class_type;
  64. typedef U qualified_class_type;
  65. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  66. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  67. };
  68. template<class T, class U, class A1>
  69. struct member_pointer<T (U::*)(A1)> {
  70. typedef T type;
  71. typedef U class_type;
  72. typedef U qualified_class_type;
  73. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  74. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  75. };
  76. template<class T, class U, class A1, class A2>
  77. struct member_pointer<T (U::*)(A1, A2)> {
  78. typedef T type;
  79. typedef U class_type;
  80. typedef U qualified_class_type;
  81. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  82. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  83. };
  84. template<class T, class U, class A1, class A2, class A3>
  85. struct member_pointer<T (U::*)(A1, A2, A3)> {
  86. typedef T type;
  87. typedef U class_type;
  88. typedef U qualified_class_type;
  89. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  90. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  91. };
  92. template<class T, class U, class A1, class A2, class A3, class A4>
  93. struct member_pointer<T (U::*)(A1, A2, A3, A4)> {
  94. typedef T type;
  95. typedef U class_type;
  96. typedef U qualified_class_type;
  97. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  98. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  99. };
  100. template<class T, class U, class A1, class A2, class A3, class A4, class A5>
  101. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5)> {
  102. typedef T type;
  103. typedef U class_type;
  104. typedef U qualified_class_type;
  105. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  106. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  107. };
  108. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  109. class A6>
  110. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6)> {
  111. typedef T type;
  112. typedef U class_type;
  113. typedef U qualified_class_type;
  114. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  115. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  116. };
  117. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  118. class A6, class A7>
  119. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7)> {
  120. typedef T type;
  121. typedef U class_type;
  122. typedef U qualified_class_type;
  123. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  124. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  125. };
  126. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  127. class A6, class A7, class A8>
  128. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8)> {
  129. typedef T type;
  130. typedef U class_type;
  131. typedef U qualified_class_type;
  132. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  133. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  134. };
  135. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  136. class A6, class A7, class A8, class A9>
  137. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
  138. typedef T type;
  139. typedef U class_type;
  140. typedef U qualified_class_type;
  141. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  142. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  143. };
  144. // -- const member functions --
  145. template<class T, class U>
  146. struct member_pointer<T (U::*)() const> {
  147. typedef T type;
  148. typedef U class_type;
  149. typedef const U qualified_class_type;
  150. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  151. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  152. };
  153. template<class T, class U, class A1>
  154. struct member_pointer<T (U::*)(A1) const> {
  155. typedef T type;
  156. typedef U class_type;
  157. typedef const U qualified_class_type;
  158. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  159. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  160. };
  161. template<class T, class U, class A1, class A2>
  162. struct member_pointer<T (U::*)(A1, A2) const> {
  163. typedef T type;
  164. typedef U class_type;
  165. typedef const U qualified_class_type;
  166. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  167. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  168. };
  169. template<class T, class U, class A1, class A2, class A3>
  170. struct member_pointer<T (U::*)(A1, A2, A3) const> {
  171. typedef T type;
  172. typedef U class_type;
  173. typedef const U qualified_class_type;
  174. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  175. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  176. };
  177. template<class T, class U, class A1, class A2, class A3, class A4>
  178. struct member_pointer<T (U::*)(A1, A2, A3, A4) const> {
  179. typedef T type;
  180. typedef U class_type;
  181. typedef const U qualified_class_type;
  182. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  183. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  184. };
  185. template<class T, class U, class A1, class A2, class A3, class A4, class A5>
  186. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5) const> {
  187. typedef T type;
  188. typedef U class_type;
  189. typedef const U qualified_class_type;
  190. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  191. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  192. };
  193. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  194. class A6>
  195. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6) const> {
  196. typedef T type;
  197. typedef U class_type;
  198. typedef const U qualified_class_type;
  199. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  200. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  201. };
  202. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  203. class A6, class A7>
  204. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7) const> {
  205. typedef T type;
  206. typedef U class_type;
  207. typedef const U qualified_class_type;
  208. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  209. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  210. };
  211. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  212. class A6, class A7, class A8>
  213. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8) const> {
  214. typedef T type;
  215. typedef U class_type;
  216. typedef const U qualified_class_type;
  217. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  218. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  219. };
  220. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  221. class A6, class A7, class A8, class A9>
  222. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const> {
  223. typedef T type;
  224. typedef U class_type;
  225. typedef const U qualified_class_type;
  226. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  227. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  228. };
  229. // -- volatile --
  230. template<class T, class U>
  231. struct member_pointer<T (U::*)() volatile> {
  232. typedef T type;
  233. typedef U class_type;
  234. typedef volatile U qualified_class_type;
  235. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  236. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  237. };
  238. template<class T, class U, class A1>
  239. struct member_pointer<T (U::*)(A1) volatile> {
  240. typedef T type;
  241. typedef U class_type;
  242. typedef volatile U qualified_class_type;
  243. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  244. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  245. };
  246. template<class T, class U, class A1, class A2>
  247. struct member_pointer<T (U::*)(A1, A2) volatile> {
  248. typedef T type;
  249. typedef U class_type;
  250. typedef volatile U qualified_class_type;
  251. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  252. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  253. };
  254. template<class T, class U, class A1, class A2, class A3>
  255. struct member_pointer<T (U::*)(A1, A2, A3) volatile> {
  256. typedef T type;
  257. typedef U class_type;
  258. typedef volatile U qualified_class_type;
  259. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  260. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  261. };
  262. template<class T, class U, class A1, class A2, class A3, class A4>
  263. struct member_pointer<T (U::*)(A1, A2, A3, A4) volatile> {
  264. typedef T type;
  265. typedef U class_type;
  266. typedef volatile U qualified_class_type;
  267. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  268. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  269. };
  270. template<class T, class U, class A1, class A2, class A3, class A4, class A5>
  271. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5) volatile> {
  272. typedef T type;
  273. typedef U class_type;
  274. typedef volatile U qualified_class_type;
  275. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  276. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  277. };
  278. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  279. class A6>
  280. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6) volatile> {
  281. typedef T type;
  282. typedef U class_type;
  283. typedef volatile U qualified_class_type;
  284. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  285. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  286. };
  287. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  288. class A6, class A7>
  289. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7) volatile> {
  290. typedef T type;
  291. typedef U class_type;
  292. typedef volatile U qualified_class_type;
  293. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  294. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  295. };
  296. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  297. class A6, class A7, class A8>
  298. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8) volatile> {
  299. typedef T type;
  300. typedef U class_type;
  301. typedef volatile U qualified_class_type;
  302. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  303. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  304. };
  305. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  306. class A6, class A7, class A8, class A9>
  307. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) volatile> {
  308. typedef T type;
  309. typedef U class_type;
  310. typedef volatile U qualified_class_type;
  311. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  312. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  313. };
  314. // -- const volatile
  315. template<class T, class U>
  316. struct member_pointer<T (U::*)() const volatile> {
  317. typedef T type;
  318. typedef U class_type;
  319. typedef const volatile U qualified_class_type;
  320. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  321. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  322. };
  323. template<class T, class U, class A1>
  324. struct member_pointer<T (U::*)(A1) const volatile> {
  325. typedef T type;
  326. typedef U class_type;
  327. typedef const volatile U qualified_class_type;
  328. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  329. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  330. };
  331. template<class T, class U, class A1, class A2>
  332. struct member_pointer<T (U::*)(A1, A2) const volatile> {
  333. typedef T type;
  334. typedef U class_type;
  335. typedef const volatile U qualified_class_type;
  336. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  337. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  338. };
  339. template<class T, class U, class A1, class A2, class A3>
  340. struct member_pointer<T (U::*)(A1, A2, A3) const volatile> {
  341. typedef T type;
  342. typedef U class_type;
  343. typedef const volatile U qualified_class_type;
  344. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  345. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  346. };
  347. template<class T, class U, class A1, class A2, class A3, class A4>
  348. struct member_pointer<T (U::*)(A1, A2, A3, A4) const volatile> {
  349. typedef T type;
  350. typedef U class_type;
  351. typedef const volatile U qualified_class_type;
  352. };
  353. template<class T, class U, class A1, class A2, class A3, class A4, class A5>
  354. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5) const volatile> {
  355. typedef T type;
  356. typedef U class_type;
  357. typedef const volatile U qualified_class_type;
  358. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  359. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  360. };
  361. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  362. class A6>
  363. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6) const volatile> {
  364. typedef T type;
  365. typedef U class_type;
  366. typedef const volatile U qualified_class_type;
  367. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  368. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  369. };
  370. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  371. class A6, class A7>
  372. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7) const volatile> {
  373. typedef T type;
  374. typedef U class_type;
  375. typedef const volatile U qualified_class_type;
  376. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  377. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  378. };
  379. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  380. class A6, class A7, class A8>
  381. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8) const volatile> {
  382. typedef T type;
  383. typedef U class_type;
  384. typedef const volatile U qualified_class_type;
  385. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  386. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  387. };
  388. template<class T, class U, class A1, class A2, class A3, class A4, class A5,
  389. class A6, class A7, class A8, class A9>
  390. struct member_pointer<T (U::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const volatile> {
  391. typedef T type;
  392. typedef U class_type;
  393. typedef const volatile U qualified_class_type;
  394. BOOST_STATIC_CONSTANT(bool, is_data_member = false);
  395. BOOST_STATIC_CONSTANT(bool, is_function_member = true);
  396. };
  397. } // detail
  398. namespace detail {
  399. // this class holds a pointer to a member function and the object.
  400. // when called, it just calls the member function with the parameters
  401. // provided
  402. // It would have been possible to use existing lambda_functors to represent
  403. // a bound member function like this, but to have a separate template is
  404. // safer, since now this functor doesn't mix and match with lambda_functors
  405. // only thing you can do with this is to call it
  406. // note that previously instantiated classes
  407. // (other_action<member_pointer_action> and member_pointer_action_helper
  408. // guarantee, that A and B are
  409. // such types, that for objects a and b of corresponding types, a->*b leads
  410. // to the builtin ->* to be called. So types that would end in a call to
  411. // a user defined ->* do not create a member_pointer_caller object.
  412. template<class RET, class A, class B>
  413. class member_pointer_caller {
  414. A a; B b;
  415. public:
  416. member_pointer_caller(const A& aa, const B& bb) : a(aa), b(bb) {}
  417. RET operator()() const { return (a->*b)(); }
  418. template<class A1>
  419. RET operator()(const A1& a1) const { return (a->*b)(a1); }
  420. template<class A1, class A2>
  421. RET operator()(const A1& a1, const A2& a2) const { return (a->*b)(a1, a2); }
  422. template<class A1, class A2, class A3>
  423. RET operator()(const A1& a1, const A2& a2, const A3& a3) const {
  424. return (a->*b)(a1, a2, a3);
  425. }
  426. template<class A1, class A2, class A3, class A4>
  427. RET operator()(const A1& a1, const A2& a2, const A3& a3,
  428. const A4& a4) const {
  429. return (a->*b)(a1, a2, a3, a4);
  430. }
  431. template<class A1, class A2, class A3, class A4, class A5>
  432. RET operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  433. const A5& a5) const {
  434. return (a->*b)(a1, a2, a3, a4, a5);
  435. }
  436. template<class A1, class A2, class A3, class A4, class A5, class A6>
  437. RET operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  438. const A5& a5, const A6& a6) const {
  439. return (a->*b)(a1, a2, a3, a4, a5, a6);
  440. }
  441. template<class A1, class A2, class A3, class A4, class A5, class A6,
  442. class A7>
  443. RET operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  444. const A5& a5, const A6& a6, const A7& a7) const {
  445. return (a->*b)(a1, a2, a3, a4, a5, a6, a7);
  446. }
  447. template<class A1, class A2, class A3, class A4, class A5, class A6,
  448. class A7, class A8>
  449. RET operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  450. const A5& a5, const A6& a6, const A7& a7,
  451. const A8& a8) const {
  452. return (a->*b)(a1, a2, a3, a4, a5, a6, a7, a8);
  453. }
  454. template<class A1, class A2, class A3, class A4, class A5, class A6,
  455. class A7, class A8, class A9>
  456. RET operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  457. const A5& a5, const A6& a6, const A7& a7,
  458. const A8& a8, const A9& a9) const {
  459. return (a->*b)(a1, a2, a3, a4, a5, a6, a7, a8, a9);
  460. }
  461. };
  462. // helper templates for return type deduction and action classes
  463. // different cases for data member, function member, neither
  464. // true-true case
  465. template <bool Is_data_member, bool Is_function_member>
  466. struct member_pointer_action_helper;
  467. // cannot be both, no body provided
  468. // data member case
  469. // this means, that B is a data member and A is a pointer type,
  470. // so either built-in ->* should be called, or there is an error
  471. template <>
  472. struct member_pointer_action_helper<true, false> {
  473. public:
  474. template<class RET, class A, class B>
  475. static RET apply(A& a, B& b) {
  476. return a->*b;
  477. }
  478. template<class A, class B>
  479. struct return_type {
  480. private:
  481. typedef typename detail::remove_reference_and_cv<B>::type plainB;
  482. typedef typename detail::member_pointer<plainB>::type type0;
  483. // we remove the reference now, as we may have to add cv:s
  484. typedef typename boost::remove_reference<type0>::type type1;
  485. // A is a reference to pointer
  486. // remove the top level cv qualifiers and reference
  487. typedef typename
  488. detail::remove_reference_and_cv<A>::type non_ref_A;
  489. // A is a pointer type, so take the type pointed to
  490. typedef typename ::boost::remove_pointer<non_ref_A>::type non_pointer_A;
  491. public:
  492. // For non-reference types, we must add const and/or volatile if
  493. // the pointer type has these qualifiers
  494. // If the member is a reference, these do not have any effect
  495. // (cv T == T if T is a reference type)
  496. typedef typename detail::IF<
  497. ::boost::is_const<non_pointer_A>::value,
  498. typename ::boost::add_const<type1>::type,
  499. type1
  500. >::RET type2;
  501. typedef typename detail::IF<
  502. ::boost::is_volatile<non_pointer_A>::value,
  503. typename ::boost::add_volatile<type2>::type,
  504. type2
  505. >::RET type3;
  506. // add reference back
  507. typedef typename ::boost::add_reference<type3>::type type;
  508. };
  509. };
  510. // neither case
  511. template <>
  512. struct member_pointer_action_helper<false, false> {
  513. public:
  514. template<class RET, class A, class B>
  515. static RET apply(A& a, B& b) {
  516. // not a built in member pointer operator, just call ->*
  517. return a->*b;
  518. }
  519. // an overloaded member pointer operators, user should have specified
  520. // the return type
  521. // At this point we know that there is no matching specialization for
  522. // return_type_2, so try return_type_2_plain
  523. template<class A, class B>
  524. struct return_type {
  525. typedef typename plain_return_type_2<
  526. other_action<member_pointer_action>, A, B
  527. >::type type;
  528. };
  529. };
  530. // member pointer function case
  531. // This is a built in ->* call for a member function,
  532. // the only thing that you can do with that, is to give it some arguments
  533. // note, it is guaranteed that A is a pointer type, and thus it cannot
  534. // be a call to overloaded ->*
  535. template <>
  536. struct member_pointer_action_helper<false, true> {
  537. public:
  538. template<class RET, class A, class B>
  539. static RET apply(A& a, B& b) {
  540. typedef typename ::boost::remove_cv<B>::type plainB;
  541. typedef typename detail::member_pointer<plainB>::type ret_t;
  542. typedef typename ::boost::remove_cv<A>::type plainA;
  543. // we always strip cv:s to
  544. // make the two routes (calling and type deduction)
  545. // to give the same results (and the const does not make any functional
  546. // difference)
  547. return detail::member_pointer_caller<ret_t, plainA, plainB>(a, b);
  548. }
  549. template<class A, class B>
  550. struct return_type {
  551. typedef typename detail::remove_reference_and_cv<B>::type plainB;
  552. typedef typename detail::member_pointer<plainB>::type ret_t;
  553. typedef typename detail::remove_reference_and_cv<A>::type plainA;
  554. typedef detail::member_pointer_caller<ret_t, plainA, plainB> type;
  555. };
  556. };
  557. } // detail
  558. template<> class other_action<member_pointer_action> {
  559. public:
  560. template<class RET, class A, class B>
  561. static RET apply(A& a, B& b) {
  562. typedef typename
  563. ::boost::remove_cv<B>::type plainB;
  564. return detail::member_pointer_action_helper<
  565. boost::is_pointer<A>::value &&
  566. detail::member_pointer<plainB>::is_data_member,
  567. boost::is_pointer<A>::value &&
  568. detail::member_pointer<plainB>::is_function_member
  569. >::template apply<RET>(a, b);
  570. }
  571. };
  572. // return type deduction --
  573. // If the right argument is a pointer to data member,
  574. // and the left argument is of compatible pointer to class type
  575. // return type is a reference to the data member type
  576. // if right argument is a pointer to a member function, and the left
  577. // argument is of a compatible type, the return type is a
  578. // member_pointer_caller (see above)
  579. // Otherwise, return type deduction fails. There is either an error,
  580. // or the user is trying to call an overloaded ->*
  581. // In such a case either ret<> must be used, or a return_type_2 user
  582. // defined specialization must be provided
  583. template<class A, class B>
  584. struct return_type_2<other_action<member_pointer_action>, A, B> {
  585. private:
  586. typedef typename
  587. detail::remove_reference_and_cv<B>::type plainB;
  588. public:
  589. typedef typename
  590. detail::member_pointer_action_helper<
  591. detail::member_pointer<plainB>::is_data_member,
  592. detail::member_pointer<plainB>::is_function_member
  593. >::template return_type<A, B>::type type;
  594. };
  595. // this is the way the generic lambda_functor_base functions instantiate
  596. // return type deduction. We turn it into return_type_2, so that the
  597. // user can provide specializations on that level.
  598. template<class Args>
  599. struct return_type_N<other_action<member_pointer_action>, Args> {
  600. typedef typename boost::tuples::element<0, Args>::type A;
  601. typedef typename boost::tuples::element<1, Args>::type B;
  602. typedef typename
  603. return_type_2<other_action<member_pointer_action>,
  604. typename boost::remove_reference<A>::type,
  605. typename boost::remove_reference<B>::type
  606. >::type type;
  607. };
  608. template<class Arg1, class Arg2>
  609. inline const
  610. lambda_functor<
  611. lambda_functor_base<
  612. action<2, other_action<member_pointer_action> >,
  613. tuple<lambda_functor<Arg1>, typename const_copy_argument<Arg2>::type>
  614. >
  615. >
  616. operator->*(const lambda_functor<Arg1>& a1, const Arg2& a2)
  617. {
  618. return
  619. lambda_functor_base<
  620. action<2, other_action<member_pointer_action> >,
  621. tuple<lambda_functor<Arg1>, typename const_copy_argument<Arg2>::type>
  622. >
  623. (tuple<lambda_functor<Arg1>,
  624. typename const_copy_argument<Arg2>::type>(a1, a2));
  625. }
  626. template<class Arg1, class Arg2>
  627. inline const
  628. lambda_functor<
  629. lambda_functor_base<
  630. action<2, other_action<member_pointer_action> >,
  631. tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
  632. >
  633. >
  634. operator->*(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2)
  635. {
  636. return
  637. lambda_functor_base<
  638. action<2, other_action<member_pointer_action> >,
  639. tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
  640. >
  641. (tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2));
  642. }
  643. template<class Arg1, class Arg2>
  644. inline const
  645. lambda_functor<
  646. lambda_functor_base<
  647. action<2, other_action<member_pointer_action> >,
  648. tuple<typename const_copy_argument<Arg1>::type, lambda_functor<Arg2> >
  649. >
  650. >
  651. operator->*(const Arg1& a1, const lambda_functor<Arg2>& a2)
  652. {
  653. return
  654. lambda_functor_base<
  655. action<2, other_action<member_pointer_action> >,
  656. tuple<typename const_copy_argument<Arg1>::type, lambda_functor<Arg2> >
  657. >
  658. (tuple<typename const_copy_argument<Arg1>::type,
  659. lambda_functor<Arg2> >(a1, a2));
  660. }
  661. } // namespace lambda
  662. } // namespace boost
  663. #endif