stl.qbk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. [/==============================================================================
  2. Copyright (C) 2001-2010 Joel de Guzman
  3. Copyright (C) 2001-2005 Dan Marsden
  4. Copyright (C) 2001-2010 Thomas Heller
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ===============================================================================/]
  8. [section STL]
  9. #include <boost/phoenix/stl.hpp>
  10. This section summarizes the lazy equivalents of C++ Standard Library functionality
  11. [section Container]
  12. #include <boost/phoenix/stl/container.hpp>
  13. The container module predefines a set of lazy functions that work on STL
  14. containers. These functions provide a mechanism for the lazy evaluation of the
  15. public member functions of the STL containers. The lazy functions are thin
  16. wrappers that simply forward to their respective counterparts in the STL
  17. library.
  18. Lazy functions are provided for all of the member functions of the following
  19. containers:
  20. * deque
  21. * list
  22. * map
  23. * multimap
  24. * vector
  25. * set
  26. * multiset
  27. Indeed, should your class have member functions with the same names and
  28. signatures as those listed below, then it will automatically be supported. To
  29. summarize, lazy functions are provided for member functions:
  30. * assign
  31. * at
  32. * back
  33. * begin
  34. * capacity
  35. * clear
  36. * empty
  37. * end
  38. * erase
  39. * front
  40. * get_allocator
  41. * insert
  42. * key_comp
  43. * max_size
  44. * pop_back
  45. * pop_front
  46. * push_back
  47. * push_front
  48. * rbegin
  49. * rend
  50. * reserve
  51. * resize
  52. * size
  53. * splice
  54. * value_comp
  55. The lazy functions' names are the same as the corresponding member function. The
  56. difference is that the lazy functions are free functions and therefore does not
  57. use the member "dot" syntax.
  58. [table Sample usage
  59. [["Normal" version] ["Lazy" version]]
  60. [[`my_vector.at(5)`] [`at(arg1, 5)`]]
  61. [[`my_list.size()`] [`size(arg1)`]]
  62. [[`my_vector1.swap(my_vector2)`] [`swap(arg1, arg2)`]]
  63. ]
  64. Notice that member functions with names that clash with stl algorithms are
  65. absent. This will be provided in Phoenix's algorithm module.
  66. No support is provided here for lazy versions of `operator+=`, `operator[]` etc.
  67. Such operators are not specific to STL containers and lazy versions can
  68. therefore be found in [link phoenix.modules.operator operators].
  69. The following table describes the container functions and their semantics.
  70. [blurb __tip__ Arguments in brackets denote optional parameters.]
  71. [table Lazy STL Container Functions
  72. [[Function] [Semantics]]
  73. [[`assign(c, a[, b, c])`] [`c.assign(a[, b, c])`]]
  74. [[`at(c, i)`] [`c.at(i)`]]
  75. [[`back(c)`] [`c.back()`]]
  76. [[`begin(c)`] [`c.begin()`]]
  77. [[`capacity(c)`] [`c.capacity()`]]
  78. [[`clear(c)`] [`c.clear()`]]
  79. [[`empty(c)`] [`c.empty()`]]
  80. [[`end(c)`] [`c.end()`]]
  81. [[`erase(c, a[, b])`] [`c.erase(a[, b])`]]
  82. [[`front(c)`] [`c.front()`]]
  83. [[`get_allocator(c)`] [`c.get_allocator()`]]
  84. [[`insert(c, a[, b, c])`] [`c.insert(a[, b, c])`]]
  85. [[`key_comp(c)`] [`c.key_comp()`]]
  86. [[`max_size(c)`] [`c.max_size()`]]
  87. [[`pop_back(c)`] [`c.pop_back()`]]
  88. [[`pop_front(c)`] [`c.pop_front()`]]
  89. [[`push_back(c, d)`] [`c.push_back(d)`]]
  90. [[`push_front(c, d)`] [`c.push_front(d)`]]
  91. [[`pop_front(c)`] [`c.pop_front()`]]
  92. [[`rbegin(c)`] [`c.rbegin()`]]
  93. [[`rend(c)`] [`c.rend()`]]
  94. [[`reserve(c, n)`] [`c.reserve(n)`]]
  95. [[`resize(c, a[, b])`] [`c.resize(a[, b])`]]
  96. [[`size(c)`] [`c.size()`]]
  97. [[`splice(c, a[, b, c, d])`] [`c.splice(a[, b, c, d])`]]
  98. [[`value_comp(c)`] [`c.value_comp()`]]
  99. ]
  100. [endsect]
  101. [section Algorithm]
  102. #include <boost/phoenix/stl/algorithm.hpp>
  103. The algorithm module provides wrappers for the standard algorithms in the
  104. `<algorithm>` and `<numeric>` headers.
  105. The algorithms are divided into the categories iteration, transformation and querying,
  106. modeling the __boost_mpl__ library. The different algorithm classes can be
  107. included using the headers:
  108. #include <boost/phoenix/stl/algorithm/iteration.hpp>
  109. #include <boost/phoenix/stl/algorithm/transformation.hpp>
  110. #include <boost/phoenix/stl/algorithm/querying.hpp>
  111. The functions of the algorithm module take ranges as arguments where
  112. appropriate. This is different to the standard
  113. library, but easy enough to pick up. Ranges are described in detail in the
  114. __boost_range__ library.
  115. For example, using the standard copy algorithm to copy between 2 arrays:
  116. int array[] = {1, 2, 3};
  117. int output[3];
  118. std::copy(array, array + 3, output); // We have to provide iterators
  119. // to both the start and end of array
  120. The analogous code using the phoenix algorithm module is:
  121. int array[] = {1, 2, 3};
  122. int output[3];
  123. copy(arg1, arg2)(array, output); // Notice only 2 arguments, the end of
  124. // array is established automatically
  125. The __boost_range__ library provides support for standard containers, strings and
  126. arrays, and can be extended to support additional types.
  127. The following tables describe the different categories of algorithms, and their
  128. semantics.
  129. [blurb __tip__ Arguments in brackets denote optional parameters.]
  130. [table Iteration Algorithms
  131. [[Function] [stl Semantics]]
  132. [[`for_each(r, f)`] [`for_each(begin(r), end(r), f)`]]
  133. [[`accumulate(r, o[, f])`] [`accumulate(begin(r), end(r), o[, f])`]]
  134. ]
  135. [table Querying Algorithms
  136. [[Function] [stl Semantics]]
  137. [[`find(r, a)`] [`find(begin(r), end(r), a)`]]
  138. [[`find_if(r, f)`] [`find_if(begin(r), end(r), f)`]]
  139. [[`find_end(r1, r2[, f])`] [`find_end(begin(r1), end(r1), begin(r2), end(r2)[, f])`]]
  140. [[`find_first_of(r1, r2[, f])`] [`find_first_of(begin(r1), end(r1), begin(r2), end(r2)[, f])`]]
  141. [[`adjacent_find(r[, f])`] [`adjacent_find(begin(r), end(r)[, f])`]]
  142. [[`count(r, a)`] [`count(begin(r), end(r), a)`]]
  143. [[`count_if(r, f)`] [`count_if(begin(r), end(r), f)`]]
  144. [[`distance(r)`] [`distance(begin(r), end(r))`]]
  145. [[`mismatch(r, i[, f])`] [`mismatch(begin(r), end(r), i[, f])`]]
  146. [[`equal(r, i[, f])`] [`equal(begin(r), end(r), i[, f])`]]
  147. [[`search(r1, r2[, f])`] [`search(begin(r1), end(r1), begin(r2), end(r2)[, f])`]]
  148. [[`lower_bound(r, a[, f])`] [`lower_bound(begin(r), end(r), a[, f])`]]
  149. [[`upper_bound(r, a[, f])`] [`upper_bound(begin(r), end(r), a[, f])`]]
  150. [[`equal_range(r, a[, f])`] [`equal_range(begin(r), end(r), a[, f])`]]
  151. [[`binary_search(r, a[, f])`] [`binary_search(begin(r), end(r), a[, f])`]]
  152. [[`includes(r1, r2[, f])`] [`includes(begin(r1), end(r1), begin(r2), end(r2)[, f])`]]
  153. [[`min_element(r[, f])`] [`min_element(begin(r), end(r)[, f])`]]
  154. [[`max_element(r[, f])`] [`max_element(begin(r), end(r)[, f])`]]
  155. [[`lexicographical_compare(r1, r2[, f])`] [`lexicographical_compare(begin(r1), end(r1), begin(r2), end(r2)[, f])`]]
  156. ]
  157. [table Transformation Algorithms
  158. [[Function] [stl Semantics] [Language Standards]]
  159. [[`copy(r, o)`] [`copy(begin(r), end(r), o)`] []]
  160. [[`copy_backward(r, o)`] [`copy_backward(begin(r), end(r), o)`] []]
  161. [[`transform(r, o, f)`] [`transform(begin(r), end(r), o, f)`] []]
  162. [[`transform(r, i, o, f)`] [`transform(begin(r), end(r), i, o, f)`] []]
  163. [[`replace(r, a, b)`] [`replace(begin(r), end(r), a, b)`] []]
  164. [[`replace_if(r, f, a)`] [`replace(begin(r), end(r), f, a)`] []]
  165. [[`replace_copy(r, o, a, b)`] [`replace_copy(begin(r), end(r), o, a, b)`] []]
  166. [[`replace_copy_if(r, o, f, a)`] [`replace_copy_if(begin(r), end(r), o, f, a)`] []]
  167. [[`fill(r, a)`] [`fill(begin(r), end(r), a)`] []]
  168. [[`fill_n(r, n, a)`] [`fill_n(begin(r), n, a)`] []]
  169. [[`generate(r, f)`] [`generate(begin(r), end(r), f)`] []]
  170. [[`generate_n(r, n, f)`] [`generate_n(begin(r), n, f)`] []]
  171. [[`remove(r, a)`] [`remove(begin(r), end(r), a)`] []]
  172. [[`remove_if(r, f)`] [`remove_if(begin(r), end(r), f)`] []]
  173. [[`remove_copy(r, o, a)`] [`remove_copy(begin(r), end(r), o, a)`] []]
  174. [[`remove_copy_if(r, o, f)`] [`remove_copy_if(begin(r), end(r), o, f)`] []]
  175. [[`unique(r[, f])`] [`unique(begin(r), end(r)[, f])`] []]
  176. [[`unique_copy(r, o[, f])`] [`unique_copy(begin(r), end(r), o[, f])`] []]
  177. [[`reverse(r)`] [`reverse(begin(r), end(r))`] []]
  178. [[`reverse_copy(r, o)`] [`reverse_copy(begin(r), end(r), o)`] []]
  179. [[`rotate(r, m)`] [`rotate(begin(r), m, end(r))`] []]
  180. [[`rotate_copy(r, m, o)`] [`rotate_copy(begin(r), m, end(r), o)`] []]
  181. [[`random_shuffle(r[, f])`] [`random_shuffle(begin(r), end(r), f)`] [Until C++17]]
  182. [[`partition(r, f)`] [`partition(begin(r), end(r), f)`] []]
  183. [[`stable_partition(r, f)`] [`stable_partition(begin(r), end(r), f)`] []]
  184. [[`sort(r[, f])`] [`sort(begin(r), end(r)[, f])`] []]
  185. [[`stable_sort(r[, f])`] [`stable_sort(begin(r), end(r)[, f])`] []]
  186. [[`partial_sort(r, m[, f])`] [`partial_sort(begin(r), m, end(r)[, f])`] []]
  187. [[`partial_sort_copy(r1, r2[, f])`] [`partial_sort_copy(begin(r1), end(r1), begin(r2), end(r2)[, f])`] []]
  188. [[`nth_element(r, n[, f])`] [`nth_element(begin(r), n, end(r)[, f])`] []]
  189. [[`merge(r1, r2, o[, f])`] [`merge(begin(r1), end(r1), begin(r2), end(r2), o[, f])`] []]
  190. [[`inplace_merge(r, m[, f])`] [`inplace_merge(begin(r), m, end(r)[, f])`] []]
  191. [[`set_union(r1, r2, o[, f])`] [`set_union(begin(r1), end(r1), begin(r2), end(r2)[, f])`] []]
  192. [[`set_intersection(r1, r2, o[, f])`] [`set_intersection(begin(r1), end(r1), begin(r2), end(r2)[, f])`] []]
  193. [[`set_difference(r1, r2, o[, f])`] [`set_difference(begin(r1), end(r1), begin(r2), end(r2)[, f])`] []]
  194. [[`set_symmetric_difference(r1, r2, o[, f])`] [`set_symmetric_difference(begin(r1), end(r1), begin(r2), end(r2)[, f])`] []]
  195. [[`push_heap(r[, f])`] [`push_heap(begin(r), end(r)[, f])`] []]
  196. [[`pop_heap(r[, f])`] [`pop_heap(begin(r), end(r)[, f])`] []]
  197. [[`make_heap(r[, f])`] [`make_heap(begin(r), end(r)[, f])`] []]
  198. [[`sort_heap(r[, f])`] [`sort_heap(begin(r), end(r)[, f])`] []]
  199. [[`next_permutation(r[, f])`] [`next_permutation(begin(r), end(r)[, f])`] []]
  200. [[`prev_permutation(r[, f])`] [`prev_permutation(begin(r), end(r)[, f])`] []]
  201. [[`inner_product(r, o, a[, f1, f2])`] [`inner_product(begin(r), end(r), o[, f1, f2])`] []]
  202. [[`partial_sum(r, o[, f])`] [`partial_sum(begin(r), end(r), o[, f])`] []]
  203. [[`adjacent_difference(r, o[, f])`] [`adjacent_difference(begin(r), end(r), o[, f])`] []]
  204. ]
  205. [endsect]
  206. [endsect]