transformation.hpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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