function_adaptors.hpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. // Boost Lambda Library - function_adaptors.hpp ----------------------------
  2. // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see www.boost.org
  9. #ifndef BOOST_LAMBDA_FUNCTION_ADAPTORS_HPP
  10. #define BOOST_LAMBDA_FUNCTION_ADAPTORS_HPP
  11. #include "boost/mpl/has_xxx.hpp"
  12. #include "boost/tuple/tuple.hpp"
  13. #include "boost/type_traits/same_traits.hpp"
  14. #include "boost/type_traits/remove_reference.hpp"
  15. #include "boost/type_traits/remove_cv.hpp"
  16. #include "boost/type_traits/add_const.hpp"
  17. #include "boost/type_traits/add_volatile.hpp"
  18. #include "boost/utility/result_of.hpp"
  19. namespace boost {
  20. namespace lambda {
  21. namespace detail {
  22. BOOST_MPL_HAS_XXX_TEMPLATE_DEF(sig)
  23. template<class Tuple>
  24. struct remove_references_from_elements {
  25. typedef typename boost::tuples::cons<
  26. typename boost::remove_reference<typename Tuple::head_type>::type,
  27. typename remove_references_from_elements<typename Tuple::tail_type>::type
  28. > type;
  29. };
  30. template<>
  31. struct remove_references_from_elements<boost::tuples::null_type> {
  32. typedef boost::tuples::null_type type;
  33. };
  34. }
  35. template <class Func> struct function_adaptor {
  36. typedef typename detail::remove_reference_and_cv<Func>::type plainF;
  37. #if !defined(BOOST_NO_RESULT_OF)
  38. // Support functors that use the boost::result_of return type convention.
  39. template<class Tuple, int Length, bool HasSig>
  40. struct result_converter;
  41. template<class Tuple, int Length>
  42. struct result_converter<Tuple, Length, true>
  43. : plainF::template sig<
  44. typename detail::remove_references_from_elements<Tuple>::type
  45. >
  46. {};
  47. template<class Tuple>
  48. struct result_converter<Tuple, 0, false>
  49. : result_of<plainF()>
  50. {};
  51. template<class Tuple>
  52. struct result_converter<Tuple, 1, false>
  53. : result_of<plainF(
  54. typename tuples::element<1, Tuple>::type)
  55. >
  56. {};
  57. template<class Tuple>
  58. struct result_converter<Tuple, 2, false>
  59. : result_of<plainF(
  60. typename tuples::element<1, Tuple>::type,
  61. typename tuples::element<2, Tuple>::type)
  62. >
  63. {};
  64. template<class Tuple>
  65. struct result_converter<Tuple, 3, false>
  66. : result_of<plainF(
  67. typename tuples::element<1, Tuple>::type,
  68. typename tuples::element<2, Tuple>::type,
  69. typename tuples::element<3, Tuple>::type)
  70. >
  71. {};
  72. template<class Tuple>
  73. struct result_converter<Tuple, 4, false>
  74. : result_of<plainF(
  75. typename tuples::element<1, Tuple>::type,
  76. typename tuples::element<2, Tuple>::type,
  77. typename tuples::element<3, Tuple>::type,
  78. typename tuples::element<4, Tuple>::type)
  79. >
  80. {};
  81. template<class Tuple>
  82. struct result_converter<Tuple, 5, false>
  83. : result_of<plainF(
  84. typename tuples::element<1, Tuple>::type,
  85. typename tuples::element<2, Tuple>::type,
  86. typename tuples::element<3, Tuple>::type,
  87. typename tuples::element<4, Tuple>::type,
  88. typename tuples::element<5, Tuple>::type)
  89. >
  90. {};
  91. template<class Tuple>
  92. struct result_converter<Tuple, 6, false>
  93. : result_of<plainF(
  94. typename tuples::element<1, Tuple>::type,
  95. typename tuples::element<2, Tuple>::type,
  96. typename tuples::element<3, Tuple>::type,
  97. typename tuples::element<4, Tuple>::type,
  98. typename tuples::element<5, Tuple>::type,
  99. typename tuples::element<6, Tuple>::type)
  100. >
  101. {};
  102. template<class Tuple>
  103. struct result_converter<Tuple, 7, false>
  104. : result_of<plainF(
  105. typename tuples::element<1, Tuple>::type,
  106. typename tuples::element<2, Tuple>::type,
  107. typename tuples::element<3, Tuple>::type,
  108. typename tuples::element<4, Tuple>::type,
  109. typename tuples::element<5, Tuple>::type,
  110. typename tuples::element<6, Tuple>::type,
  111. typename tuples::element<7, Tuple>::type)
  112. >
  113. {};
  114. template<class Tuple>
  115. struct result_converter<Tuple, 8, false>
  116. : result_of<plainF(
  117. typename tuples::element<1, Tuple>::type,
  118. typename tuples::element<2, Tuple>::type,
  119. typename tuples::element<3, Tuple>::type,
  120. typename tuples::element<4, Tuple>::type,
  121. typename tuples::element<5, Tuple>::type,
  122. typename tuples::element<6, Tuple>::type,
  123. typename tuples::element<7, Tuple>::type,
  124. typename tuples::element<8, Tuple>::type)
  125. >
  126. {};
  127. template<class Tuple>
  128. struct result_converter<Tuple, 9, false>
  129. : result_of<plainF(
  130. typename tuples::element<1, Tuple>::type,
  131. typename tuples::element<2, Tuple>::type,
  132. typename tuples::element<3, Tuple>::type,
  133. typename tuples::element<4, Tuple>::type,
  134. typename tuples::element<5, Tuple>::type,
  135. typename tuples::element<6, Tuple>::type,
  136. typename tuples::element<7, Tuple>::type,
  137. typename tuples::element<8, Tuple>::type,
  138. typename tuples::element<9, Tuple>::type)
  139. >
  140. {};
  141. // we do not know the return type off-hand, we must ask it from Func
  142. // To sig we pass a cons list, where the head is the function object type
  143. // itself (potentially cv-qualified)
  144. // and the tail contains the types of the actual arguments to be passed
  145. // to the function object. The arguments can be cv qualified
  146. // as well.
  147. template <class Args>
  148. struct sig
  149. : result_converter<
  150. Args
  151. , tuples::length<typename Args::tail_type>::value
  152. , detail::has_sig<plainF>::value
  153. >
  154. {};
  155. #else // BOOST_NO_RESULT_OF
  156. template <class Args> class sig {
  157. typedef typename detail::remove_reference_and_cv<Func>::type plainF;
  158. public:
  159. typedef typename plainF::template sig<
  160. typename detail::remove_references_from_elements<Args>::type
  161. >::type type;
  162. };
  163. #endif
  164. template<class RET, class A1>
  165. static RET apply(A1& a1) {
  166. return a1();
  167. }
  168. template<class RET, class A1, class A2>
  169. static RET apply(A1& a1, A2& a2) {
  170. return a1(a2);
  171. }
  172. template<class RET, class A1, class A2, class A3>
  173. static RET apply(A1& a1, A2& a2, A3& a3) {
  174. return a1(a2, a3);
  175. }
  176. template<class RET, class A1, class A2, class A3, class A4>
  177. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4) {
  178. return a1(a2, a3, a4);
  179. }
  180. template<class RET, class A1, class A2, class A3, class A4, class A5>
  181. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  182. return a1(a2, a3, a4, a5);
  183. }
  184. template<class RET, class A1, class A2, class A3, class A4, class A5, class A6>
  185. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  186. return a1(a2, a3, a4, a5, a6);
  187. }
  188. template<class RET, class A1, class A2, class A3, class A4, class A5, class A6,
  189. class A7>
  190. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6,
  191. A7& a7) {
  192. return a1(a2, a3, a4, a5, a6, a7);
  193. }
  194. template<class RET, class A1, class A2, class A3, class A4, class A5, class A6,
  195. class A7, class A8>
  196. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6,
  197. A7& a7, A8& a8) {
  198. return a1(a2, a3, a4, a5, a6, a7, a8);
  199. }
  200. template<class RET, class A1, class A2, class A3, class A4, class A5, class A6,
  201. class A7, class A8, class A9>
  202. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6,
  203. A7& a7, A8& a8, A9& a9) {
  204. return a1(a2, a3, a4, a5, a6, a7, a8, a9);
  205. }
  206. template<class RET, class A1, class A2, class A3, class A4, class A5, class A6,
  207. class A7, class A8, class A9, class A10>
  208. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6,
  209. A7& a7, A8& a8, A9& a9, A10& a10) {
  210. return a1(a2, a3, a4, a5, a6, a7, a8, a9, a10);
  211. }
  212. };
  213. template <class Func> struct function_adaptor<const Func>; // error
  214. // -- function adaptors with data member access
  215. template <class Object, class T>
  216. struct function_adaptor<T Object::*> {
  217. // typedef detail::unspecified type;
  218. // T can have qualifiers and can be a reference type
  219. // We get the return type by adding const, if the object through which
  220. // the data member is accessed is const, and finally adding a reference
  221. template<class Args> class sig {
  222. typedef typename boost::tuples::element<1, Args>::type argument_type;
  223. typedef typename boost::remove_reference<
  224. argument_type
  225. >::type unref_type;
  226. typedef typename detail::IF<boost::is_const<unref_type>::value,
  227. typename boost::add_const<T>::type,
  228. T
  229. >::RET properly_consted_return_type;
  230. typedef typename detail::IF<boost::is_volatile<unref_type>::value,
  231. typename boost::add_volatile<properly_consted_return_type>::type,
  232. properly_consted_return_type
  233. >::RET properly_cvd_return_type;
  234. public:
  235. typedef typename detail::IF<boost::is_reference<argument_type>::value,
  236. typename boost::add_reference<properly_cvd_return_type>::type,
  237. typename boost::remove_cv<T>::type
  238. >::RET type;
  239. };
  240. template <class RET>
  241. static RET apply( T Object::*data, Object& o) {
  242. return o.*data;
  243. }
  244. template <class RET>
  245. static RET apply( T Object::*data, const Object& o) {
  246. return o.*data;
  247. }
  248. template <class RET>
  249. static RET apply( T Object::*data, volatile Object& o) {
  250. return o.*data;
  251. }
  252. template <class RET>
  253. static RET apply( T Object::*data, const volatile Object& o) {
  254. return o.*data;
  255. }
  256. template <class RET>
  257. static RET apply( T Object::*data, Object* o) {
  258. return o->*data;
  259. }
  260. template <class RET>
  261. static RET apply( T Object::*data, const Object* o) {
  262. return o->*data;
  263. }
  264. template <class RET>
  265. static RET apply( T Object::*data, volatile Object* o) {
  266. return o->*data;
  267. }
  268. template <class RET>
  269. static RET apply( T Object::*data, const volatile Object* o) {
  270. return o->*data;
  271. }
  272. };
  273. // -- function adaptors with 1 argument apply
  274. template <class Result>
  275. struct function_adaptor<Result (void)> {
  276. template<class T> struct sig { typedef Result type; };
  277. template <class RET>
  278. static Result apply(Result (*func)()) {
  279. return func();
  280. }
  281. };
  282. template <class Result>
  283. struct function_adaptor<Result (*)(void)> {
  284. template<class T> struct sig { typedef Result type; };
  285. template <class RET>
  286. static Result apply(Result (*func)()) {
  287. return func();
  288. }
  289. };
  290. // -- function adaptors with 2 argument apply
  291. template <class Object, class Result>
  292. struct function_adaptor<Result (Object::*)() const> {
  293. template<class T> struct sig { typedef Result type; };
  294. template <class RET>
  295. static Result apply( Result (Object::*func)() const, const Object* o) {
  296. return (o->*func)();
  297. }
  298. template <class RET>
  299. static Result apply( Result (Object::*func)() const, const Object& o) {
  300. return (o.*func)();
  301. }
  302. };
  303. template <class Object, class Result>
  304. struct function_adaptor<Result (Object::*)()> {
  305. template<class T> struct sig { typedef Result type; };
  306. template <class RET>
  307. static Result apply( Result (Object::*func)(), Object* o) {
  308. return (o->*func)();
  309. }
  310. template <class RET>
  311. static Result apply( Result (Object::*func)(), Object& o) {
  312. return (o.*func)();
  313. }
  314. };
  315. template <class Arg1, class Result>
  316. struct function_adaptor<Result (Arg1)> {
  317. template<class T> struct sig { typedef Result type; };
  318. template <class RET, class A1>
  319. static Result apply(Result (*func)(Arg1), A1& a1) {
  320. return func(a1);
  321. }
  322. };
  323. template <class Arg1, class Result>
  324. struct function_adaptor<Result (*)(Arg1)> {
  325. template<class T> struct sig { typedef Result type; };
  326. template <class RET, class A1>
  327. static Result apply(Result (*func)(Arg1), A1& a1) {
  328. return func(a1);
  329. }
  330. };
  331. // -- function adaptors with 3 argument apply
  332. template <class Object, class Arg1, class Result>
  333. struct function_adaptor<Result (Object::*)(Arg1) const> {
  334. template<class T> struct sig { typedef Result type; };
  335. template <class RET, class A1>
  336. static Result apply( Result (Object::*func)(Arg1) const, const Object* o,
  337. A1& a1) {
  338. return (o->*func)(a1);
  339. }
  340. template <class RET, class A1>
  341. static Result apply( Result (Object::*func)(Arg1) const, const Object& o,
  342. A1& a1) {
  343. return (o.*func)(a1);
  344. }
  345. };
  346. template <class Object, class Arg1, class Result>
  347. struct function_adaptor<Result (Object::*)(Arg1)> {
  348. template<class T> struct sig { typedef Result type; };
  349. template <class RET, class A1>
  350. static Result apply( Result (Object::*func)(Arg1), Object* o, A1& a1) {
  351. return (o->*func)(a1);
  352. }
  353. template <class RET, class A1>
  354. static Result apply( Result (Object::*func)(Arg1), Object& o, A1& a1) {
  355. return (o.*func)(a1);
  356. }
  357. };
  358. template <class Arg1, class Arg2, class Result>
  359. struct function_adaptor<Result (Arg1, Arg2)> {
  360. template<class T> struct sig { typedef Result type; };
  361. template <class RET, class A1, class A2>
  362. static Result apply(Result (*func)(Arg1, Arg2), A1& a1, A2& a2) {
  363. return func(a1, a2);
  364. }
  365. };
  366. template <class Arg1, class Arg2, class Result>
  367. struct function_adaptor<Result (*)(Arg1, Arg2)> {
  368. template<class T> struct sig { typedef Result type; };
  369. template <class RET, class A1, class A2>
  370. static Result apply(Result (*func)(Arg1, Arg2), A1& a1, A2& a2) {
  371. return func(a1, a2);
  372. }
  373. };
  374. // -- function adaptors with 4 argument apply
  375. template <class Object, class Arg1, class Arg2, class Result>
  376. struct function_adaptor<Result (Object::*)(Arg1, Arg2) const> {
  377. template<class T> struct sig { typedef Result type; };
  378. template <class RET, class A1, class A2>
  379. static Result apply( Result (Object::*func)(Arg1, Arg2) const, const Object* o, A1& a1, A2& a2) {
  380. return (o->*func)(a1, a2);
  381. }
  382. template <class RET, class A1, class A2>
  383. static Result apply( Result (Object::*func)(Arg1, Arg2) const, const Object& o, A1& a1, A2& a2) {
  384. return (o.*func)(a1, a2);
  385. }
  386. };
  387. template <class Object, class Arg1, class Arg2, class Result>
  388. struct function_adaptor<Result (Object::*)(Arg1, Arg2)> {
  389. template<class T> struct sig { typedef Result type; };
  390. template <class RET, class A1, class A2>
  391. static Result apply( Result (Object::*func)(Arg1, Arg2), Object* o, A1& a1, A2& a2) {
  392. return (o->*func)(a1, a2);
  393. }
  394. template <class RET, class A1, class A2>
  395. static Result apply( Result (Object::*func)(Arg1, Arg2), Object& o, A1& a1, A2& a2) {
  396. return (o.*func)(a1, a2);
  397. }
  398. };
  399. template <class Arg1, class Arg2, class Arg3, class Result>
  400. struct function_adaptor<Result (Arg1, Arg2, Arg3)> {
  401. template<class T> struct sig { typedef Result type; };
  402. template <class RET, class A1, class A2, class A3>
  403. static Result apply(Result (*func)(Arg1, Arg2, Arg3), A1& a1, A2& a2, A3& a3) {
  404. return func(a1, a2, a3);
  405. }
  406. };
  407. template <class Arg1, class Arg2, class Arg3, class Result>
  408. struct function_adaptor<Result (*)(Arg1, Arg2, Arg3)> {
  409. template<class T> struct sig { typedef Result type; };
  410. template <class RET, class A1, class A2, class A3>
  411. static Result apply(Result (*func)(Arg1, Arg2, Arg3), A1& a1, A2& a2, A3& a3) {
  412. return func(a1, a2, a3);
  413. }
  414. };
  415. // -- function adaptors with 5 argument apply
  416. template <class Object, class Arg1, class Arg2, class Arg3, class Result>
  417. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3) const> {
  418. template<class T> struct sig { typedef Result type; };
  419. template <class RET, class A1, class A2, class A3>
  420. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3) const, const Object* o, A1& a1, A2& a2, A3& a3) {
  421. return (o->*func)(a1, a2, a3);
  422. }
  423. template <class RET, class A1, class A2, class A3>
  424. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3) const, const Object& o, A1& a1, A2& a2, A3& a3) {
  425. return (o.*func)(a1, a2, a3);
  426. }
  427. };
  428. template <class Object, class Arg1, class Arg2, class Arg3, class Result>
  429. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3)> {
  430. template<class T> struct sig { typedef Result type; };
  431. template <class RET, class A1, class A2, class A3>
  432. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3), Object* o, A1& a1, A2& a2, A3& a3) {
  433. return (o->*func)(a1, a2, a3);
  434. }
  435. template <class RET, class A1, class A2, class A3>
  436. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3), Object& o, A1& a1, A2& a2, A3& a3) {
  437. return (o.*func)(a1, a2, a3);
  438. }
  439. };
  440. template <class Arg1, class Arg2, class Arg3, class Arg4, class Result>
  441. struct function_adaptor<Result (Arg1, Arg2, Arg3, Arg4)> {
  442. template<class T> struct sig { typedef Result type; };
  443. template <class RET, class A1, class A2, class A3, class A4>
  444. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4), A1& a1, A2& a2, A3& a3, A4& a4) {
  445. return func(a1, a2, a3, a4);
  446. }
  447. };
  448. template <class Arg1, class Arg2, class Arg3, class Arg4, class Result>
  449. struct function_adaptor<Result (*)(Arg1, Arg2, Arg3, Arg4)> {
  450. template<class T> struct sig { typedef Result type; };
  451. template <class RET, class A1, class A2, class A3, class A4>
  452. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4), A1& a1, A2& a2, A3& a3, A4& a4) {
  453. return func(a1, a2, a3, a4);
  454. }
  455. };
  456. // -- function adaptors with 6 argument apply
  457. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Result>
  458. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4) const> {
  459. template<class T> struct sig { typedef Result type; };
  460. template <class RET, class A1, class A2, class A3, class A4>
  461. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4) const, const Object* o, A1& a1, A2& a2, A3& a3, A4& a4) {
  462. return (o->*func)(a1, a2, a3, a4);
  463. }
  464. template <class RET, class A1, class A2, class A3, class A4>
  465. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4) const, const Object& o, A1& a1, A2& a2, A3& a3, A4& a4) {
  466. return (o.*func)(a1, a2, a3, a4);
  467. }
  468. };
  469. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Result>
  470. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4)> {
  471. template<class T> struct sig { typedef Result type; };
  472. template <class RET, class A1, class A2, class A3, class A4>
  473. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4), Object* o, A1& a1, A2& a2, A3& a3, A4& a4) {
  474. return (o->*func)(a1, a2, a3, a4);
  475. }
  476. template <class RET, class A1, class A2, class A3, class A4>
  477. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4), Object& o, A1& a1, A2& a2, A3& a3, A4& a4) {
  478. return (o.*func)(a1, a2, a3, a4);
  479. }
  480. };
  481. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Result>
  482. struct function_adaptor<Result (Arg1, Arg2, Arg3, Arg4, Arg5)> {
  483. template<class T> struct sig { typedef Result type; };
  484. template <class RET, class A1, class A2, class A3, class A4, class A5>
  485. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  486. return func(a1, a2, a3, a4, a5);
  487. }
  488. };
  489. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Result>
  490. struct function_adaptor<Result (*)(Arg1, Arg2, Arg3, Arg4, Arg5)> {
  491. template<class T> struct sig { typedef Result type; };
  492. template <class RET, class A1, class A2, class A3, class A4, class A5>
  493. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  494. return func(a1, a2, a3, a4, a5);
  495. }
  496. };
  497. // -- function adaptors with 7 argument apply
  498. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Result>
  499. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5) const> {
  500. template<class T> struct sig { typedef Result type; };
  501. template <class RET, class A1, class A2, class A3, class A4, class A5>
  502. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5) const, const Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  503. return (o->*func)(a1, a2, a3, a4, a5);
  504. }
  505. template <class RET, class A1, class A2, class A3, class A4, class A5>
  506. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5) const, const Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  507. return (o.*func)(a1, a2, a3, a4, a5);
  508. }
  509. };
  510. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Result>
  511. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5)> {
  512. template<class T> struct sig { typedef Result type; };
  513. template <class RET, class A1, class A2, class A3, class A4, class A5>
  514. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5), Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  515. return (o->*func)(a1, a2, a3, a4, a5);
  516. }
  517. template <class RET, class A1, class A2, class A3, class A4, class A5>
  518. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5), Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  519. return (o.*func)(a1, a2, a3, a4, a5);
  520. }
  521. };
  522. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Result>
  523. struct function_adaptor<Result (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)> {
  524. template<class T> struct sig { typedef Result type; };
  525. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6>
  526. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  527. return func(a1, a2, a3, a4, a5, a6);
  528. }
  529. };
  530. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Result>
  531. struct function_adaptor<Result (*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)> {
  532. template<class T> struct sig { typedef Result type; };
  533. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6>
  534. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  535. return func(a1, a2, a3, a4, a5, a6);
  536. }
  537. };
  538. // -- function adaptors with 8 argument apply
  539. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Result>
  540. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) const> {
  541. template<class T> struct sig { typedef Result type; };
  542. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6>
  543. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) const, const Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  544. return (o->*func)(a1, a2, a3, a4, a5, a6);
  545. }
  546. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6>
  547. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) const, const Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  548. return (o.*func)(a1, a2, a3, a4, a5, a6);
  549. }
  550. };
  551. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Result>
  552. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)> {
  553. template<class T> struct sig { typedef Result type; };
  554. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6>
  555. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  556. return (o->*func)(a1, a2, a3, a4, a5, a6);
  557. }
  558. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6>
  559. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  560. return (o.*func)(a1, a2, a3, a4, a5, a6);
  561. }
  562. };
  563. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Result>
  564. struct function_adaptor<Result (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)> {
  565. template<class T> struct sig { typedef Result type; };
  566. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
  567. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7) {
  568. return func(a1, a2, a3, a4, a5, a6, a7);
  569. }
  570. };
  571. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Result>
  572. struct function_adaptor<Result (*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)> {
  573. template<class T> struct sig { typedef Result type; };
  574. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
  575. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7) {
  576. return func(a1, a2, a3, a4, a5, a6, a7);
  577. }
  578. };
  579. // -- function adaptors with 9 argument apply
  580. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Result>
  581. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) const> {
  582. template<class T> struct sig { typedef Result type; };
  583. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
  584. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) const, const Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7) {
  585. return (o->*func)(a1, a2, a3, a4, a5, a6, a7);
  586. }
  587. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
  588. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) const, const Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7) {
  589. return (o.*func)(a1, a2, a3, a4, a5, a6, a7);
  590. }
  591. };
  592. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Result>
  593. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)> {
  594. template<class T> struct sig { typedef Result type; };
  595. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
  596. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7), Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7) {
  597. return (o->*func)(a1, a2, a3, a4, a5, a6, a7);
  598. }
  599. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
  600. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7), Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7) {
  601. return (o.*func)(a1, a2, a3, a4, a5, a6, a7);
  602. }
  603. };
  604. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Result>
  605. struct function_adaptor<Result (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)> {
  606. template<class T> struct sig { typedef Result type; };
  607. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
  608. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8) {
  609. return func(a1, a2, a3, a4, a5, a6, a7, a8);
  610. }
  611. };
  612. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Result>
  613. struct function_adaptor<Result (*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)> {
  614. template<class T> struct sig { typedef Result type; };
  615. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
  616. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8) {
  617. return func(a1, a2, a3, a4, a5, a6, a7, a8);
  618. }
  619. };
  620. // -- function adaptors with 10 argument apply
  621. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Result>
  622. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) const> {
  623. template<class T> struct sig { typedef Result type; };
  624. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
  625. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) const, const Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8) {
  626. return (o->*func)(a1, a2, a3, a4, a5, a6, a7, a8);
  627. }
  628. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
  629. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) const, const Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8) {
  630. return (o.*func)(a1, a2, a3, a4, a5, a6, a7, a8);
  631. }
  632. };
  633. template <class Object, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Result>
  634. struct function_adaptor<Result (Object::*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)> {
  635. template<class T> struct sig { typedef Result type; };
  636. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
  637. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8), Object* o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8) {
  638. return (o->*func)(a1, a2, a3, a4, a5, a6, a7, a8);
  639. }
  640. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
  641. static Result apply( Result (Object::*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8), Object& o, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8) {
  642. return (o.*func)(a1, a2, a3, a4, a5, a6, a7, a8);
  643. }
  644. };
  645. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Arg9, class Result>
  646. struct function_adaptor<Result (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)> {
  647. template<class T> struct sig { typedef Result type; };
  648. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
  649. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8, A9& a9) {
  650. return func(a1, a2, a3, a4, a5, a6, a7, a8, a9);
  651. }
  652. };
  653. template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Arg9, class Result>
  654. struct function_adaptor<Result (*)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)> {
  655. template<class T> struct sig { typedef Result type; };
  656. template <class RET, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
  657. static Result apply(Result (*func)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9), A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8, A9& a9) {
  658. return func(a1, a2, a3, a4, a5, a6, a7, a8, a9);
  659. }
  660. };
  661. } // namespace lambda
  662. } // namespace boost
  663. #endif