transformation.hpp 33 KB

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