transformation.hpp 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. // Copyright 2005 Daniel Wallin.
  2. // Copyright 2005 Joel de Guzman.
  3. // Copyright 2005 Dan Marsden.
  4. // Copyright 2015 John Fletcher.
  5. //
  6. // Use, modification and distribution is subject to the Boost Software
  7. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Modeled after range_ex, Copyright 2004 Eric Niebler
  11. #ifndef BOOST_PHOENIX_ALGORITHM_TRANSFORMATION_HPP
  12. #define BOOST_PHOENIX_ALGORITHM_TRANSFORMATION_HPP
  13. #include <algorithm>
  14. #include <numeric>
  15. #include <boost/phoenix/core/limits.hpp>
  16. #include <boost/phoenix/stl/algorithm/detail/has_sort.hpp>
  17. #include <boost/phoenix/stl/algorithm/detail/has_remove.hpp>
  18. #include <boost/phoenix/stl/algorithm/detail/has_remove_if.hpp>
  19. #include <boost/phoenix/stl/algorithm/detail/has_unique.hpp>
  20. #include <boost/phoenix/stl/algorithm/detail/has_reverse.hpp>
  21. #include <boost/phoenix/stl/algorithm/detail/has_sort.hpp>
  22. #include <boost/phoenix/stl/algorithm/detail/begin.hpp>
  23. #include <boost/phoenix/stl/algorithm/detail/end.hpp>
  24. #include <boost/phoenix/stl/algorithm/detail/decay_array.hpp>
  25. #include <boost/phoenix/function/adapt_callable.hpp>
  26. //#include <boost/range/result_iterator.hpp> is deprecated
  27. #include <boost/range/iterator.hpp>
  28. #include <boost/range/difference_type.hpp>
  29. #include <boost/mpl/if.hpp>
  30. #include <boost/type_traits/is_void.hpp>
  31. namespace boost { namespace phoenix { namespace impl
  32. {
  33. struct swap
  34. {
  35. typedef void result_type;
  36. template <class A, class B>
  37. void operator()(A& a, B& b) const
  38. {
  39. using std::swap;
  40. swap(a, b);
  41. }
  42. };
  43. struct copy
  44. {
  45. template <typename Sig>
  46. struct result;
  47. template<typename This, class R, class I>
  48. struct result<This(R&, I)>
  49. : detail::decay_array<I>
  50. {};
  51. template<class R, class I>
  52. typename detail::decay_array<I>::type
  53. operator()(R& r, I i) const
  54. {
  55. return std::copy(detail::begin_(r), detail::end_(r), i);
  56. }
  57. };
  58. struct copy_backward
  59. {
  60. template <typename Sig>
  61. struct result;
  62. template<typename This, class R, class I>
  63. struct result<This(R&, I)>
  64. : result<This(R&, I const &)>
  65. {};
  66. template<typename This, class R, class I>
  67. struct result<This(R&, I &)>
  68. {
  69. typedef I type;
  70. };
  71. template<class R, class I>
  72. I operator()(R& r, I & i) const
  73. {
  74. return std::copy_backward(detail::begin_(r), detail::end_(r), i);
  75. }
  76. template<class R, class I>
  77. I const operator()(R& r, I const & i) const
  78. {
  79. return std::copy_backward(detail::begin_(r), detail::end_(r), i);
  80. }
  81. };
  82. struct transform
  83. {
  84. template <typename Sig>
  85. struct result;
  86. template<typename This, class R, class OutorI1, class ForOut>
  87. struct result<This(R&, OutorI1, ForOut)>
  88. : detail::decay_array<OutorI1>
  89. {
  90. };
  91. template<typename This, class R, class OutorI1, class ForOut, class BinF>
  92. struct result<This(R&, OutorI1, ForOut, BinF)>
  93. : detail::decay_array<ForOut>
  94. {
  95. };
  96. template<class R, class O, class F>
  97. typename result<transform(R&,O,F)>::type
  98. operator()(R& r, O o, F f) const
  99. {
  100. return std::transform(detail::begin_(r), detail::end_(r), o, f);
  101. }
  102. template<class R, class I, class O, class F>
  103. typename result<transform(R&,I,O,F)>::type
  104. operator()(R& r, I i, O o, F f) const
  105. {
  106. return std::transform(detail::begin_(r), detail::end_(r), i, o, f);
  107. }
  108. };
  109. struct replace
  110. {
  111. typedef void result_type;
  112. template<class R, class T>
  113. void operator()(R& r, T const& what, T const& with) const
  114. {
  115. std::replace(detail::begin_(r), detail::end_(r), what, with);
  116. }
  117. };
  118. struct replace_if
  119. {
  120. typedef void result_type;
  121. template<class R, class P, class T>
  122. void operator()(R& r, P p, T const& with) const
  123. {
  124. std::replace_if(detail::begin_(r), detail::end_(r), p, with);
  125. }
  126. };
  127. struct replace_copy
  128. {
  129. template <typename Sig>
  130. struct result;
  131. template<typename This, class R, class O, class T, class T2>
  132. struct result<This(R&, O, T&, T2&)>
  133. : detail::decay_array<O>
  134. {};
  135. template<class R, class O, class T>
  136. typename detail::decay_array<O>::type
  137. operator()(R& r, O o, T const& what, T const& with) const
  138. {
  139. return std::replace_copy(detail::begin_(r), detail::end_(r), o, what, with);
  140. }
  141. };
  142. struct replace_copy_if
  143. {
  144. template <typename Sig>
  145. struct result;
  146. template<typename This, class R, class O, class P, class T>
  147. struct result<This(R&, O, P, T&)>
  148. : detail::decay_array<O>
  149. {};
  150. template<class R, class O, class P, class T>
  151. typename detail::decay_array<O>::type
  152. operator()(R& r, O o, P p, T const& with) const
  153. {
  154. return std::replace_copy_if(detail::begin_(r), detail::end_(r), o, p, with);
  155. }
  156. };
  157. struct fill
  158. {
  159. typedef void result_type;
  160. template<class R, class T>
  161. void operator()(R& r, T const& x) const
  162. {
  163. std::fill(detail::begin_(r), detail::end_(r), x);
  164. }
  165. };
  166. struct fill_n
  167. {
  168. typedef void result_type;
  169. template<class R, class N, class T>
  170. void operator()(R& r, N n, T const& x) const
  171. {
  172. std::fill_n(detail::begin_(r), n, x);
  173. }
  174. };
  175. struct generate
  176. {
  177. typedef void result_type;
  178. template<class R, class G>
  179. void operator()(R& r, G const & g) const
  180. {
  181. std::generate(detail::begin_(r), detail::end_(r), g);
  182. }
  183. };
  184. struct generate_n
  185. {
  186. typedef void result_type;
  187. template<class R, class N, class G>
  188. void operator()(R& r, N n, G g) const
  189. {
  190. std::generate_n(detail::begin_(r), n, g);
  191. }
  192. };
  193. struct remove
  194. {
  195. template <typename Sig>
  196. struct result;
  197. template<typename This, class R, class T>
  198. struct result<This(R&, T&)>
  199. : range_iterator<R>
  200. {
  201. };
  202. template<class R, class T>
  203. typename range_iterator<R>::type
  204. execute(R& r, T const& x, mpl::true_) const
  205. {
  206. r.remove(x);
  207. return detail::end_(r);
  208. }
  209. template<class R, class T>
  210. typename range_iterator<R>::type
  211. execute(R& r, T const& x, mpl::false_) const
  212. {
  213. return std::remove(detail::begin_(r), detail::end_(r), x);
  214. }
  215. template<class R, class T>
  216. typename range_iterator<R>::type
  217. operator()(R& r, T const& x) const
  218. {
  219. return execute(r, x, has_remove<R>());
  220. }
  221. };
  222. struct remove_if
  223. {
  224. template <typename Sig>
  225. struct result;
  226. template <typename This, class R, class P>
  227. struct result<This(R&,P)>
  228. : range_iterator<R>
  229. {
  230. };
  231. template<class R, class P>
  232. typename range_iterator<R>::type
  233. execute(R& r, P p, mpl::true_) const
  234. {
  235. r.remove_if(p);
  236. return detail::end_(r);
  237. }
  238. template<class R, class P>
  239. typename range_iterator<R>::type
  240. execute(R& r, P p, mpl::false_) const
  241. {
  242. return std::remove_if(detail::begin_(r), detail::end_(r), p);
  243. }
  244. template<class R, class P>
  245. typename range_iterator<R>::type
  246. operator()(R& r, P p) const
  247. {
  248. return execute(r, p, has_remove_if<R>());
  249. }
  250. };
  251. struct remove_copy
  252. {
  253. template <typename Sig>
  254. struct result;
  255. template<typename This, class R, class O, class T>
  256. struct result<This(R&, O, T)>
  257. : detail::decay_array<O>
  258. {};
  259. template<class R, class O, class T>
  260. typename detail::decay_array<O>::type
  261. operator()(R& r, O o, T const& x) const
  262. {
  263. return std::remove_copy(detail::begin_(r), detail::end_(r), o, x);
  264. }
  265. };
  266. struct remove_copy_if
  267. {
  268. template <typename Sig>
  269. struct result;
  270. template<typename This, class R, class O, class P>
  271. struct result<This(R&, O, P)>
  272. : detail::decay_array<O>
  273. {};
  274. template<class R, class O, class P>
  275. typename detail::decay_array<O>::type
  276. operator()(R& r, O o, P p) const
  277. {
  278. return std::remove_copy_if(detail::begin_(r), detail::end_(r), o, p);
  279. }
  280. };
  281. struct unique
  282. {
  283. template <typename Sig>
  284. struct result;
  285. template<typename This, class R>
  286. struct result<This(R&)>
  287. : range_iterator<R>
  288. {};
  289. template<typename This, class R, class P>
  290. struct result<This(R&, P)>
  291. : range_iterator<R>
  292. {};
  293. template<class R>
  294. typename range_iterator<R>::type
  295. execute(R& r, mpl::true_) const
  296. {
  297. r.unique();
  298. return detail::end_(r);
  299. }
  300. template<class R>
  301. typename range_iterator<R>::type
  302. execute(R& r, mpl::false_) const
  303. {
  304. return std::unique(detail::begin_(r), detail::end_(r));
  305. }
  306. template<class R>
  307. typename range_iterator<R>::type
  308. operator()(R& r) const
  309. {
  310. return execute(r, has_unique<R>());
  311. }
  312. template<class R, class P>
  313. typename range_iterator<R>::type
  314. execute(R& r, P p, mpl::true_) const
  315. {
  316. r.unique(p);
  317. return detail::end_(r);
  318. }
  319. template<class R, class P>
  320. typename range_iterator<R>::type
  321. execute(R& r, P p, mpl::false_) const
  322. {
  323. return std::unique(detail::begin_(r), detail::end_(r), p);
  324. }
  325. template<class R, class P>
  326. typename range_iterator<R>::type
  327. operator()(R& r, P p) const
  328. {
  329. return execute(r, p, has_unique<R>());
  330. }
  331. };
  332. struct unique_copy
  333. {
  334. template <typename Sig>
  335. struct result;
  336. template<typename This, class R, class O>
  337. struct result<This(R&, O)>
  338. : detail::decay_array<O>
  339. {};
  340. template<typename This, class R, class O, class P>
  341. struct result<This(R&, O, P)>
  342. : detail::decay_array<O>
  343. {};
  344. template<class R, class O>
  345. typename detail::decay_array<O>::type operator()(R& r, O o) const
  346. {
  347. return std::unique_copy(
  348. detail::begin_(r)
  349. , detail::end_(r)
  350. , o
  351. );
  352. }
  353. template<class R, class O, class P>
  354. typename detail::decay_array<O>::type operator()(R& r, O o, P p) const
  355. {
  356. return std::unique_copy(
  357. detail::begin_(r)
  358. , detail::end_(r)
  359. , o
  360. , p
  361. );
  362. }
  363. };
  364. struct reverse
  365. {
  366. typedef void result_type;
  367. template<class R>
  368. void execute(R& r, mpl::true_) const
  369. {
  370. r.reverse();
  371. }
  372. template<class R>
  373. void execute(R& r, mpl::false_) const
  374. {
  375. std::reverse(detail::begin_(r), detail::end_(r));
  376. }
  377. template<class R>
  378. void operator()(R& r) const
  379. {
  380. execute(r, has_reverse<R>());
  381. }
  382. };
  383. struct reverse_copy
  384. {
  385. template <typename Sig>
  386. struct result;
  387. template<typename This, class R, class O>
  388. struct result<This(R&, O)>
  389. : detail::decay_array<O>
  390. {};
  391. template<class R, class O>
  392. typename detail::decay_array<O>::type operator()(R& r, O o) const
  393. {
  394. return std::reverse_copy(
  395. detail::begin_(r)
  396. , detail::end_(r)
  397. , o
  398. );
  399. }
  400. };
  401. struct rotate
  402. {
  403. typedef void result_type;
  404. template<class R, class M>
  405. void operator()(R& r, M m) const
  406. {
  407. std::rotate(
  408. detail::begin_(r)
  409. , m
  410. , detail::end_(r)
  411. );
  412. }
  413. };
  414. struct rotate_copy
  415. {
  416. template <typename Sig>
  417. struct result;
  418. template<typename This, class R, class M, class O>
  419. struct result<This(R&, M, O)>
  420. : detail::decay_array<O>
  421. {};
  422. template<class R, class M, class O>
  423. typename detail::decay_array<O>::type operator()(R& r, M m, O o) const
  424. {
  425. return std::rotate_copy(
  426. detail::begin_(r)
  427. , m
  428. , detail::end_(r)
  429. , o
  430. );
  431. }
  432. };
  433. #ifndef BOOST_NO_CXX98_RANDOM_SHUFFLE
  434. struct random_shuffle
  435. {
  436. typedef void result_type;
  437. template<class R>
  438. void operator()(R& r) const
  439. {
  440. return std::random_shuffle(detail::begin_(r), detail::end_(r));
  441. }
  442. template<class R, class G>
  443. void operator()(R& r, G g) const
  444. {
  445. return std::random_shuffle(detail::begin_(r), detail::end_(r), g);
  446. }
  447. };
  448. #endif
  449. struct partition
  450. {
  451. template <typename Sig>
  452. struct result;
  453. template <typename This, class R, class P>
  454. struct result<This(R&, P)>
  455. : range_iterator<R>
  456. {};
  457. template<class R, class P>
  458. typename range_iterator<R>::type
  459. operator()(R& r, P p) const
  460. {
  461. return std::partition(detail::begin_(r), detail::end_(r), p);
  462. }
  463. };
  464. struct stable_partition
  465. {
  466. template <typename Sig>
  467. struct result;
  468. template <typename This, class R, class P>
  469. struct result<This(R&, P)>
  470. : range_iterator<R>
  471. {};
  472. template<class R, class P>
  473. typename range_iterator<R>::type
  474. operator()(R& r, P p) const
  475. {
  476. return std::stable_partition(detail::begin_(r), detail::end_(r), p);
  477. }
  478. };
  479. struct sort
  480. {
  481. typedef void result_type;
  482. template<class R>
  483. void execute(R& r, mpl::true_) const
  484. {
  485. r.sort();
  486. }
  487. template<class R>
  488. void execute(R& r, mpl::false_) const
  489. {
  490. std::sort(detail::begin_(r), detail::end_(r));
  491. }
  492. template<class R>
  493. void operator()(R& r) const
  494. {
  495. execute(r, has_sort<R>());
  496. }
  497. template<class R, class C>
  498. void execute(R& r, C c, mpl::true_) const
  499. {
  500. r.sort(c);
  501. }
  502. template<class R, class C>
  503. void execute(R& r, C c, mpl::false_) const
  504. {
  505. std::sort(detail::begin_(r), detail::end_(r), c);
  506. }
  507. template<class R, class C>
  508. void operator()(R& r, C c) const
  509. {
  510. execute(r, c, has_sort<R>());
  511. }
  512. };
  513. struct stable_sort
  514. {
  515. typedef void result_type;
  516. template<class R>
  517. void operator()(R& r) const
  518. {
  519. std::stable_sort(detail::begin_(r), detail::end_(r));
  520. }
  521. template<class R, class C>
  522. void operator()(R& r, C c) const
  523. {
  524. std::stable_sort(detail::begin_(r), detail::end_(r), c);
  525. }
  526. };
  527. struct partial_sort
  528. {
  529. typedef void result_type;
  530. template<class R, class M>
  531. void operator()(R& r, M m) const
  532. {
  533. std::partial_sort(detail::begin_(r), m, detail::end_(r));
  534. }
  535. template<class R, class M, class C>
  536. void operator()(R& r, M m, C c) const
  537. {
  538. std::partial_sort(detail::begin_(r), m, detail::end_(r), c);
  539. }
  540. };
  541. struct partial_sort_copy
  542. {
  543. template <typename Sig>
  544. struct result;
  545. template <typename This, class R1, class R2>
  546. struct result<This(R1&, R2&)>
  547. : range_iterator<R2>
  548. {};
  549. template <typename This, class R1, class R2, class C>
  550. struct result<This(R1&, R2&, C)>
  551. : range_iterator<R2>
  552. {};
  553. template <class R1, class R2>
  554. typename range_iterator<R2>::type
  555. operator()(R1& r1, R2& r2) const
  556. {
  557. return std::partial_sort_copy(
  558. detail::begin_(r1), detail::end_(r1)
  559. , detail::begin_(r2), detail::end_(r2)
  560. );
  561. }
  562. template <class R1, class R2, class C>
  563. typename range_iterator<R2>::type
  564. operator()(R1& r1, R2& r2, C c) const
  565. {
  566. return std::partial_sort_copy(
  567. detail::begin_(r1), detail::end_(r1)
  568. , detail::begin_(r2), detail::end_(r2)
  569. , c
  570. );
  571. }
  572. };
  573. struct nth_element
  574. {
  575. typedef void result_type;
  576. template<class R, class N>
  577. void operator()(R& r, N n) const
  578. {
  579. return std::nth_element(detail::begin_(r), n, detail::end_(r));
  580. }
  581. template<class R, class N, class C>
  582. void operator()(R& r, N n, C c) const
  583. {
  584. return std::nth_element(detail::begin_(r), n, detail::end_(r), c);
  585. }
  586. };
  587. struct merge
  588. {
  589. template <typename Sig>
  590. struct result;
  591. template<typename This, class R1, class R2, class O>
  592. struct result<This(R1&, R2&, O)>
  593. : detail::decay_array<O>
  594. {};
  595. template<typename This, class R1, class R2, class O, class C>
  596. struct result<This(R1&, R2&, O, C)>
  597. : detail::decay_array<O>
  598. {};
  599. template<class R1, class R2, class O>
  600. typename detail::decay_array<O>::type operator()(R1& r1, R2& r2, O o) const
  601. {
  602. return std::merge(
  603. detail::begin_(r1), detail::end_(r1)
  604. , detail::begin_(r2), detail::end_(r2)
  605. , o
  606. );
  607. }
  608. template<class R1, class R2, class O, class C>
  609. typename detail::decay_array<O>::type operator()(R1& r1, R2& r2, O o, C c) const
  610. {
  611. return std::merge(
  612. detail::begin_(r1), detail::end_(r1)
  613. , detail::begin_(r2), detail::end_(r2)
  614. , o
  615. , c
  616. );
  617. }
  618. };
  619. struct inplace_merge
  620. {
  621. typedef void result_type;
  622. template<class R, class M>
  623. void operator()(R& r, M m) const
  624. {
  625. return std::inplace_merge(detail::begin_(r), m, detail::end_(r));
  626. }
  627. template<class R, class M, class C>
  628. void operator()(R& r, M m, C c) const
  629. {
  630. return std::inplace_merge(detail::begin_(r), m, detail::end_(r), c);
  631. }
  632. };
  633. struct next_permutation
  634. {
  635. typedef bool result_type;
  636. template<class R>
  637. bool operator()(R& r) const
  638. {
  639. return std::next_permutation(detail::begin_(r), detail::end_(r));
  640. }
  641. template<class R, class C>
  642. bool operator()(R& r, C c) const
  643. {
  644. return std::next_permutation(detail::begin_(r), detail::end_(r), c);
  645. }
  646. };
  647. struct prev_permutation
  648. {
  649. typedef bool result_type;
  650. template<class R>
  651. bool operator()(R& r) const
  652. {
  653. return std::prev_permutation(detail::begin_(r), detail::end_(r));
  654. }
  655. template<class R, class C>
  656. bool operator()(R& r, C c) const
  657. {
  658. return std::prev_permutation(detail::begin_(r), detail::end_(r), c);
  659. }
  660. };
  661. struct inner_product
  662. {
  663. template <typename Sig>
  664. struct result;
  665. template <typename This, typename R, typename I, typename T>
  666. struct result<This(R&, I, T)>
  667. : result<This(R&, I const &, T)>
  668. {};
  669. template <typename This, typename R, typename I, typename T>
  670. struct result<This(R&, I, T &)>
  671. {
  672. typedef T type;
  673. };
  674. template <typename This, typename R, typename I, typename T, typename C1, typename C2>
  675. struct result<This(R&, I, T, C1, C2)>
  676. : result<This(R&, I, T const &, C1, C2)>
  677. {};
  678. template <typename This, typename R, typename I, typename T, typename C1, typename C2>
  679. struct result<This(R&, I, T &, C1, C2)>
  680. {
  681. typedef T type;
  682. };
  683. template <class R, class I, class T>
  684. T
  685. operator()(R& r, I i, T t) const
  686. {
  687. return std::inner_product(
  688. detail::begin_(r), detail::end_(r), i, t);
  689. }
  690. template <class R, class I, class T, class C1, class C2>
  691. T
  692. operator()(R& r, I i, T t, C1 c1, C2 c2) const
  693. {
  694. return std::inner_product(
  695. detail::begin_(r), detail::end_(r), i,
  696. t, c1, c2);
  697. }
  698. };
  699. struct partial_sum
  700. {
  701. template <typename Sig>
  702. struct result;
  703. template <typename This, class R, class I>
  704. struct result<This(R&, I)>
  705. : detail::decay_array<I>
  706. {};
  707. template <typename This, class R, class I, class C>
  708. struct result<This(R&, I, C)>
  709. : detail::decay_array<I>
  710. {};
  711. template <class R, class I>
  712. typename detail::decay_array<I>::type
  713. operator()(R& r, I i) const
  714. {
  715. return std::partial_sum(
  716. detail::begin_(r), detail::end_(r), i);
  717. }
  718. template <class R, class I, class C>
  719. typename detail::decay_array<I>::type
  720. operator()(R& r, I i, C c) const
  721. {
  722. return std::partial_sum(
  723. detail::begin_(r), detail::end_(r), i, c);
  724. }
  725. };
  726. struct adjacent_difference
  727. {
  728. template <typename Sig>
  729. struct result;
  730. template <typename This, class R, class I>
  731. struct result<This(R&, I)>
  732. : detail::decay_array<I>
  733. {};
  734. template <typename This,class R, class I, class C>
  735. struct result<This(R&, I, C)>
  736. : detail::decay_array<I>
  737. {};
  738. template <class R, class I>
  739. typename detail::decay_array<I>::type
  740. operator()(R& r, I i) const
  741. {
  742. return std::adjacent_difference(
  743. detail::begin_(r), detail::end_(r), i);
  744. }
  745. template <class R, class I, class C>
  746. typename detail::decay_array<I>::type
  747. operator()(R& r, I i, C c) const
  748. {
  749. return std::adjacent_difference(
  750. detail::begin_(r), detail::end_(r), i, c);
  751. }
  752. };
  753. struct push_heap
  754. {
  755. typedef void result_type;
  756. template <class R>
  757. void operator()(R& r) const
  758. {
  759. std::push_heap(detail::begin_(r), detail::end_(r));
  760. }
  761. template <class R, class C>
  762. void operator()(R& r, C c) const
  763. {
  764. std::push_heap(detail::begin_(r), detail::end_(r), c);
  765. }
  766. };
  767. struct pop_heap
  768. {
  769. typedef void result_type;
  770. template <class R>
  771. void operator()(R& r) const
  772. {
  773. std::pop_heap(detail::begin_(r), detail::end_(r));
  774. }
  775. template <class R, class C>
  776. void operator()(R& r, C c) const
  777. {
  778. std::pop_heap(detail::begin_(r), detail::end_(r), c);
  779. }
  780. };
  781. struct make_heap
  782. {
  783. typedef void result_type;
  784. template <class R>
  785. void operator()(R& r) const
  786. {
  787. std::make_heap(detail::begin_(r), detail::end_(r));
  788. }
  789. template <class R, class C>
  790. void operator()(R& r, C c) const
  791. {
  792. std::make_heap(detail::begin_(r), detail::end_(r), c);
  793. }
  794. };
  795. struct sort_heap
  796. {
  797. typedef void result_type;
  798. template <class R>
  799. void operator()(R& r) const
  800. {
  801. std::sort_heap(detail::begin_(r), detail::end_(r));
  802. }
  803. template <class R, class C>
  804. void operator()(R& r, C c) const
  805. {
  806. std::sort_heap(detail::begin_(r), detail::end_(r), c);
  807. }
  808. };
  809. struct set_union
  810. {
  811. template <typename Sig>
  812. struct result;
  813. template <typename This, class R1, class R2, class O>
  814. struct result<This(R1&, R2&, O)>
  815. : detail::decay_array<O>
  816. {};
  817. template <typename This, class R1, class R2, class O, typename C>
  818. struct result<This(R1&, R2&, O, C)>
  819. : detail::decay_array<O>
  820. {};
  821. template <class R1, class R2, class O>
  822. typename detail::decay_array<O>::type
  823. operator()(R1& r1, R2& r2, O o) const
  824. {
  825. return std::set_union(
  826. detail::begin_(r1), detail::end_(r1)
  827. , detail::begin_(r2), detail::end_(r2)
  828. , o
  829. );
  830. }
  831. template <class R1, class R2, class O, class C>
  832. typename detail::decay_array<O>::type
  833. operator()(R1& r1, R2& r2, O o, C c) const
  834. {
  835. return std::set_union(
  836. detail::begin_(r1), detail::end_(r1)
  837. , detail::begin_(r2), detail::end_(r2)
  838. , o
  839. , c
  840. );
  841. }
  842. };
  843. struct set_intersection
  844. {
  845. template <typename Sig>
  846. struct result;
  847. template <typename This, class R1, class R2, class O>
  848. struct result<This(R1&, R2&, O)>
  849. : detail::decay_array<O>
  850. {};
  851. template <typename This, class R1, class R2, class O, typename C>
  852. struct result<This(R1&, R2&, O, C)>
  853. : detail::decay_array<O>
  854. {};
  855. template <class R1, class R2, class O>
  856. typename detail::decay_array<O>::type
  857. operator()(R1& r1, R2& r2, O o) const
  858. {
  859. return std::set_intersection(
  860. detail::begin_(r1), detail::end_(r1)
  861. , detail::begin_(r2), detail::end_(r2)
  862. , o
  863. );
  864. }
  865. template <class R1, class R2, class O, class C>
  866. typename detail::decay_array<O>::type
  867. operator()(R1& r1, R2& r2, O o, C c) const
  868. {
  869. return std::set_intersection(
  870. detail::begin_(r1), detail::end_(r1)
  871. , detail::begin_(r2), detail::end_(r2)
  872. , o
  873. , c
  874. );
  875. }
  876. };
  877. struct set_difference
  878. {
  879. template <typename Sig>
  880. struct result;
  881. template <typename This, class R1, class R2, class O>
  882. struct result<This(R1&, R2&, O)>
  883. : detail::decay_array<O>
  884. {};
  885. template <typename This, class R1, class R2, class O, class C>
  886. struct result<This(R1&, R2&, O, C)>
  887. : detail::decay_array<O>
  888. {};
  889. template <class R1, class R2, class O>
  890. typename detail::decay_array<O>::type
  891. operator()(R1& r1, R2& r2, O o) const
  892. {
  893. return std::set_difference(
  894. detail::begin_(r1), detail::end_(r1)
  895. , detail::begin_(r2), detail::end_(r2)
  896. , o
  897. );
  898. }
  899. template <class R1, class R2, class O, class C>
  900. typename detail::decay_array<O>::type
  901. operator()(R1& r1, R2& r2, O o, C c) const
  902. {
  903. return std::set_difference(
  904. detail::begin_(r1), detail::end_(r1)
  905. , detail::begin_(r2), detail::end_(r2)
  906. , o
  907. , c
  908. );
  909. }
  910. };
  911. struct set_symmetric_difference
  912. {
  913. template <typename Sig>
  914. struct result;
  915. template <typename This, class R1, class R2, class O>
  916. struct result<This(R1&, R2, O)>
  917. : detail::decay_array<O>
  918. {};
  919. template <typename This, class R1, class R2, class O, class C>
  920. struct result<This(R1&, R2, O, C)>
  921. : detail::decay_array<O>
  922. {};
  923. template <class R1, class R2, class O>
  924. typename detail::decay_array<O>::type
  925. operator()(R1& r1, R2& r2, O o) const
  926. {
  927. return std::set_symmetric_difference(
  928. detail::begin_(r1), detail::end_(r1)
  929. , detail::begin_(r2), detail::end_(r2)
  930. , o
  931. );
  932. }
  933. template <class R1, class R2, class O, class C>
  934. typename detail::decay_array<O>::type
  935. operator()(R1& r1, R2& r2, O o, C c) const
  936. {
  937. return std::set_symmetric_difference(
  938. detail::begin_(r1), detail::end_(r1)
  939. , detail::begin_(r2), detail::end_(r2)
  940. , o
  941. , c
  942. );
  943. }
  944. };
  945. }}} // boost::phoenix::impl
  946. namespace boost { namespace phoenix
  947. {
  948. BOOST_PHOENIX_ADAPT_CALLABLE(swap, impl::swap, 2)
  949. BOOST_PHOENIX_ADAPT_CALLABLE(copy, impl::copy, 2)
  950. BOOST_PHOENIX_ADAPT_CALLABLE(copy_backward, impl::copy_backward, 2)
  951. BOOST_PHOENIX_ADAPT_CALLABLE(transform, impl::transform, 3)
  952. BOOST_PHOENIX_ADAPT_CALLABLE(transform, impl::transform, 4)
  953. BOOST_PHOENIX_ADAPT_CALLABLE(replace, impl::replace, 3)
  954. BOOST_PHOENIX_ADAPT_CALLABLE(replace_if, impl::replace_if, 3)
  955. BOOST_PHOENIX_ADAPT_CALLABLE(replace_copy, impl::replace_copy, 4)
  956. BOOST_PHOENIX_ADAPT_CALLABLE(replace_copy_if, impl::replace_copy_if, 4)
  957. BOOST_PHOENIX_ADAPT_CALLABLE(fill, impl::fill, 2)
  958. BOOST_PHOENIX_ADAPT_CALLABLE(fill_n, impl::fill_n, 3)
  959. BOOST_PHOENIX_ADAPT_CALLABLE(generate, impl::generate, 2)
  960. BOOST_PHOENIX_ADAPT_CALLABLE(generate_n, impl::generate_n, 3)
  961. BOOST_PHOENIX_ADAPT_CALLABLE(remove, impl::remove, 2)
  962. BOOST_PHOENIX_ADAPT_CALLABLE(remove_if, impl::remove_if, 2)
  963. BOOST_PHOENIX_ADAPT_CALLABLE(remove_copy, impl::remove_copy, 3)
  964. BOOST_PHOENIX_ADAPT_CALLABLE(remove_copy_if, impl::remove_copy_if, 3)
  965. BOOST_PHOENIX_ADAPT_CALLABLE(unique, impl::unique, 1)
  966. BOOST_PHOENIX_ADAPT_CALLABLE(unique, impl::unique, 2)
  967. BOOST_PHOENIX_ADAPT_CALLABLE(unique_copy, impl::unique_copy, 2)
  968. BOOST_PHOENIX_ADAPT_CALLABLE(unique_copy, impl::unique_copy, 3)
  969. BOOST_PHOENIX_ADAPT_CALLABLE(reverse, impl::reverse, 1)
  970. BOOST_PHOENIX_ADAPT_CALLABLE(reverse_copy, impl::reverse_copy, 2)
  971. BOOST_PHOENIX_ADAPT_CALLABLE(rotate, impl::rotate, 2)
  972. BOOST_PHOENIX_ADAPT_CALLABLE(rotate_copy, impl::rotate_copy, 3)
  973. #ifndef BOOST_NO_CXX98_RANDOM_SHUFFLE
  974. BOOST_PHOENIX_ADAPT_CALLABLE(random_shuffle, impl::random_shuffle, 1)
  975. BOOST_PHOENIX_ADAPT_CALLABLE(random_shuffle, impl::random_shuffle, 2)
  976. #endif
  977. BOOST_PHOENIX_ADAPT_CALLABLE(partition, impl::partition, 2)
  978. BOOST_PHOENIX_ADAPT_CALLABLE(stable_partition, impl::stable_partition, 2)
  979. BOOST_PHOENIX_ADAPT_CALLABLE(sort, impl::sort, 1)
  980. BOOST_PHOENIX_ADAPT_CALLABLE(sort, impl::sort, 2)
  981. BOOST_PHOENIX_ADAPT_CALLABLE(stable_sort, impl::stable_sort, 1)
  982. BOOST_PHOENIX_ADAPT_CALLABLE(stable_sort, impl::stable_sort, 2)
  983. BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort, impl::partial_sort, 2)
  984. BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort, impl::partial_sort, 3)
  985. BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort_copy, impl::partial_sort_copy, 2)
  986. BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort_copy, impl::partial_sort_copy, 3)
  987. BOOST_PHOENIX_ADAPT_CALLABLE(nth_element, impl::nth_element, 2)
  988. BOOST_PHOENIX_ADAPT_CALLABLE(nth_element, impl::nth_element, 3)
  989. BOOST_PHOENIX_ADAPT_CALLABLE(merge, impl::merge, 3)
  990. BOOST_PHOENIX_ADAPT_CALLABLE(merge, impl::merge, 4)
  991. BOOST_PHOENIX_ADAPT_CALLABLE(inplace_merge, impl::inplace_merge, 2)
  992. BOOST_PHOENIX_ADAPT_CALLABLE(inplace_merge, impl::inplace_merge, 3)
  993. BOOST_PHOENIX_ADAPT_CALLABLE(next_permutation, impl::next_permutation, 1)
  994. BOOST_PHOENIX_ADAPT_CALLABLE(next_permutation, impl::next_permutation, 2)
  995. BOOST_PHOENIX_ADAPT_CALLABLE(prev_permutation, impl::prev_permutation, 1)
  996. BOOST_PHOENIX_ADAPT_CALLABLE(prev_permutation, impl::prev_permutation, 2)
  997. BOOST_PHOENIX_ADAPT_CALLABLE(inner_product, impl::inner_product, 3)
  998. BOOST_PHOENIX_ADAPT_CALLABLE(inner_product, impl::inner_product, 5)
  999. BOOST_PHOENIX_ADAPT_CALLABLE(partial_sum, impl::partial_sum, 2)
  1000. BOOST_PHOENIX_ADAPT_CALLABLE(partial_sum, impl::partial_sum, 3)
  1001. BOOST_PHOENIX_ADAPT_CALLABLE(adjacent_difference, impl::adjacent_difference, 2)
  1002. BOOST_PHOENIX_ADAPT_CALLABLE(adjacent_difference, impl::adjacent_difference, 3)
  1003. BOOST_PHOENIX_ADAPT_CALLABLE(push_heap, impl::push_heap, 1)
  1004. BOOST_PHOENIX_ADAPT_CALLABLE(push_heap, impl::push_heap, 2)
  1005. BOOST_PHOENIX_ADAPT_CALLABLE(pop_heap, impl::pop_heap, 1)
  1006. BOOST_PHOENIX_ADAPT_CALLABLE(pop_heap, impl::pop_heap, 2)
  1007. BOOST_PHOENIX_ADAPT_CALLABLE(make_heap, impl::make_heap, 1)
  1008. BOOST_PHOENIX_ADAPT_CALLABLE(make_heap, impl::make_heap, 2)
  1009. BOOST_PHOENIX_ADAPT_CALLABLE(sort_heap, impl::sort_heap, 1)
  1010. BOOST_PHOENIX_ADAPT_CALLABLE(sort_heap, impl::sort_heap, 2)
  1011. BOOST_PHOENIX_ADAPT_CALLABLE(set_union, impl::set_union, 3)
  1012. BOOST_PHOENIX_ADAPT_CALLABLE(set_union, impl::set_union, 4)
  1013. BOOST_PHOENIX_ADAPT_CALLABLE(set_intersection, impl::set_intersection, 3)
  1014. BOOST_PHOENIX_ADAPT_CALLABLE(set_intersection, impl::set_intersection, 4)
  1015. BOOST_PHOENIX_ADAPT_CALLABLE(set_difference, impl::set_difference, 3)
  1016. BOOST_PHOENIX_ADAPT_CALLABLE(set_difference, impl::set_difference, 4)
  1017. BOOST_PHOENIX_ADAPT_CALLABLE(set_symmetric_difference, impl::set_symmetric_difference, 3)
  1018. BOOST_PHOENIX_ADAPT_CALLABLE(set_symmetric_difference, impl::set_symmetric_difference, 4)
  1019. }}
  1020. #endif