semantics.qbk 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. [/
  2. Copyright 2010 Neil Groves
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. /]
  6. [section:semantics Semantics]
  7. [heading notation]
  8. [table
  9. [[Type ] [Object] [Describes ]]
  10. [[`X` ] [`x` ] [any type ]]
  11. [[`T` ] [`t` ] [denotes behavior of the primary templates]]
  12. [[`P` ] [`p` ] [denotes `std::pair<iterator,iterator>` ]]
  13. [[`A[sz]`] [`a` ] [denotes an array of type `A` of size `sz`]]
  14. [[`Char*`] [`s` ] [denotes either `char*` or `wchar_t*` ]]
  15. ]
  16. [section Metafunctions]
  17. [table
  18. [[Expression] [Return type] [Complexity]]
  19. [
  20. [`range_iterator<X>::type`]
  21. [``
  22. T::iterator
  23. P::first_type
  24. A*
  25. ``]
  26. [compile time]
  27. ]
  28. [
  29. [`range_iterator<const X>::type`]
  30. [``
  31. T::const_iterator
  32. P::first_type
  33. const A*
  34. ``]
  35. [compile time]
  36. ]
  37. [
  38. [`range_value<X>::type`]
  39. [`boost::iterator_value<range_iterator<X>::type>::type`]
  40. [compile time]
  41. ]
  42. [
  43. [`range_reference<X>::type`]
  44. [`boost::iterator_reference<range_iterator<X>::type>::type`]
  45. [compile time]
  46. ]
  47. [
  48. [`range_pointer<X>::type`]
  49. [`boost::iterator_pointer<range_iterator<X>::type>::type`]
  50. [compile time]
  51. ]
  52. [
  53. [`range_category<X>::type`]
  54. [`boost::iterator_category<range_iterator<X>::type>::type`]
  55. [compile time]
  56. ]
  57. [
  58. [`range_difference<X>::type`]
  59. [`boost::iterator_difference<range_iterator<X>::type>::type`]
  60. [compile time]
  61. ]
  62. [
  63. [`range_reverse_iterator<X>::type`]
  64. [`boost::reverse_iterator<range_iterator<X>::type>`]
  65. [compile time]
  66. ]
  67. [
  68. [`range_reverse_iterator<const X>::type`]
  69. [`boost::reverse_iterator<range_iterator<const X>::type`]
  70. [compile time]
  71. ]
  72. [
  73. [`has_range_iterator<X>::type`]
  74. [`mpl::true_` if `range_mutable_iterator<X>::type` is a valid expression, `mpl::false_` otherwise]
  75. [compile time]
  76. ]
  77. [
  78. [`has_range_const_iterator<X>::type`]
  79. [`mpl::true_` if `range_const_iterator<X>::type` is a valid expression, `mpl::false_` otherwise]
  80. [compile time]
  81. ]
  82. ]
  83. [endsect]
  84. [section Functions]
  85. [table
  86. [[Expression] [Return type] [Returns] [Complexity]]
  87. [
  88. [`begin(x)`]
  89. [`range_iterator<X>::type`]
  90. [
  91. `p.first` if `p` is of type `std::pair<T>`
  92. `a` if `a` is an array
  93. `range_begin(x)` if that expression would invoke a function found by ADL
  94. `t.begin()` otherwise
  95. ]
  96. [constant time]
  97. ]
  98. [
  99. [`end(x)`]
  100. [`range_iterator<X>::type`]
  101. [
  102. `p.second` if `p` is of type `std::pair<T>`
  103. `a + sz` if `a` is an array of size `sz`
  104. `range_end(x)` if that expression would invoke a function found by ADL
  105. `t.end()` otherwise
  106. ]
  107. [constant time]
  108. ]
  109. [
  110. [`empty(x)`]
  111. [`bool`]
  112. [`boost::begin(x) == boost::end(x)`]
  113. [constant time]
  114. ]
  115. [
  116. [`distance(x)`]
  117. [`range_difference<X>::type`]
  118. [`std::distance(boost::begin(x),boost::end(x))`]
  119. [-]
  120. ]
  121. [
  122. [`size(x)`]
  123. [`range_size<X>::type`]
  124. [`range_calculate_size(x)` which by default is `boost::end(x) - boost::begin(x)`. Users may supply alternative implementations by implementing `range_calculate_size(x)` so that it will be found via ADL]
  125. [constant time]
  126. ]
  127. [
  128. [`rbegin(x)`]
  129. [`range_reverse_iterator<X>::type`]
  130. [`range_reverse_iterator<X>::type(boost::end(x))`]
  131. [constant time]
  132. ]
  133. [
  134. [`rend(x)`]
  135. [`range_reverse_iterator<X>::type`]
  136. [`range_reverse_iterator<X>::type(boost::begin(x))`]
  137. [constant time]
  138. ]
  139. [
  140. [`const_begin(x)`]
  141. [`range_iterator<const X>::type`]
  142. [`range_iterator<const X>::type(boost::begin(x))`]
  143. [constant time]
  144. ]
  145. [
  146. [`const_end(x)`]
  147. [`range_iterator<const X>::type`]
  148. [`range_iterator<const X>::type(boost::end(x))`]
  149. [constant time]
  150. ]
  151. [
  152. [`const_rbegin(x)`]
  153. [`range_reverse_iterator<const X>::type`]
  154. [`range_reverse_iterator<const X>::type(boost::rbegin(x))`]
  155. [constant time]
  156. ]
  157. [
  158. [`const_rend(x)`]
  159. [`range_reverse_iterator<const X>::type`]
  160. [`range_reverse_iterator<const X>::type(boost::rend(x))`]
  161. [constant time]
  162. ]
  163. [
  164. [`as_literal(x)`]
  165. [`iterator_range<U>` where `U` is `Char*` if `x` is a pointer to a string and `U` is `range_iterator<X>::type` otherwise]
  166. [
  167. `[s,s + std::char_traits<X>::length(s))` if `s` is a `Char*` or an array of `Char` `[boost::begin(x),boost::end(x))` otherwise
  168. ]
  169. [
  170. linear time for pointers to a string or arrays of `Char`, constant time otherwise
  171. ]
  172. ]
  173. [
  174. [`as_array(x)`]
  175. [`iterator_range<X>`]
  176. [`[boost::begin(x),boost::end(x))`]
  177. ]
  178. ]
  179. The special `const_`-named functions are useful when you want to document clearly that your code is read-only.
  180. `as_literal()` can be used ['*internally*] in string algorithm libraries such that arrays of characters are handled correctly.
  181. `as_array()` can be used with string algorithm libraries to make it clear that arrays of characters are handled like an array and not like a string.
  182. Notice that the above functions should always be called with qualification (`boost::`) to prevent ['*unintended*] Argument Dependent Lookup (ADL).
  183. [endsect]
  184. [endsect]