sequence.qbk 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2006 Dan Marsden
  4. Copyright (C) 2014 Christoph Weiss
  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. [section Sequence]
  10. Like __mpl__, the Sequence is a fundamental concept in Fusion. A Sequence
  11. may or may not actually store or contain data. __containers__ are sequences
  12. that hold data. __views__, on the other hand, are sequences that do not
  13. store any data. Instead, they are proxies that impart an alternative
  14. presentation over another sequence. All models of Sequence have an
  15. associated __iterator__ type that can be used to iterate through the
  16. Sequence's elements.
  17. [heading Header]
  18. #include <boost/fusion/sequence.hpp>
  19. #include <boost/fusion/include/sequence.hpp>
  20. [section Concepts]
  21. Fusion Sequences are organized into a hierarchy of concepts.
  22. [heading Traversal]
  23. Fusion's sequence traversal related concepts parallel Fusion's
  24. __iterator_concepts__. __forward_sequence__ is the most basic concept.
  25. __bidirectional_sequence__ is a refinement of __forward_sequence__.
  26. __random_access_sequence__ is a refinement of __bidirectional_sequence__.
  27. These concepts pertain to sequence traversal.
  28. [heading Associativity]
  29. The __associative_sequence__ concept is orthogonal to traversal. An Associative
  30. Sequence allows efficient retrieval of elements based on keys.
  31. [heading Boundary]
  32. The __unbounded_sequence__ concept is also orthogonal to traversal and associativity.
  33. A Unbounded Sequence allows out-of-bounds access.
  34. [section Forward Sequence]
  35. [heading Description]
  36. A Forward Sequence is a Sequence whose elements are arranged in a definite
  37. order. The ordering is guaranteed not to change from iteration to
  38. iteration. The requirement of a definite ordering allows the definition of
  39. element-by-element equality (if the container's element type is Equality
  40. Comparable) and of lexicographical ordering (if the container's element
  41. type is LessThan Comparable).
  42. [variablelist Notation
  43. [[`s`] [A Forward Sequence]]
  44. [[`S`] [A Forward Sequence type]]
  45. [[`o`] [An arbitrary object]]
  46. [[`e`] [A Sequence element]]
  47. ]
  48. [heading Valid Expressions]
  49. For any Forward Sequence the following expressions must be valid:
  50. [table
  51. [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
  52. [[`__begin__(s)`] [__forward_iterator__] [] [Constant]]
  53. [[`__end__(s)`] [__forward_iterator__] [] [Constant]]
  54. [[`__size__(s)`] [__mpl_integral_constant__.
  55. Convertible to int.] [] [Constant]]
  56. [[`__empty__(s)`] [__mpl_boolean_constant__.
  57. Convertible to bool.] [] [Constant]]
  58. [[`__front__(s)`] [Any type] [] [Constant]]
  59. [[`__front__(s) = o`] [Any type] [`s` is mutable and
  60. `e = o`, where `e`
  61. is the first element
  62. in the sequence, is
  63. a valid expression.] [Constant]]
  64. ]
  65. [heading Result Type Expressions]
  66. [table
  67. [[Expression] [Compile Time Complexity]]
  68. [[`__result_of_begin__<S>::type`] [Amortized constant time]]
  69. [[`__result_of_end__<S>::type`] [Amortized constant time]]
  70. [[`__result_of_size__<S>::type`] [Unspecified]]
  71. [[`__result_of_empty__<S>::type`] [Constant time]]
  72. [[`__result_of_front__<S>::type`] [Amortized constant time]]
  73. ]
  74. [heading Expression Semantics]
  75. [table
  76. [[Expression] [Semantics]]
  77. [[`__begin__(s)`] [An iterator to the first element of the sequence; see __begin__.]]
  78. [[`__end__(s)`] [A past-the-end iterator to the sequence; see __end__.]]
  79. [[`__size__(s)`] [The size of the sequence; see __size__.]]
  80. [[`__empty__(s)`] [A boolean Integral Constant `c` such that
  81. `c::value == true` if and only if the sequence
  82. is empty; see __empty__.]]
  83. [[`__front__(s)`] [The first element in the sequence; see __front__.]]
  84. ]
  85. [heading Invariants]
  86. For any Forward Sequence s the following invariants always hold:
  87. * `[__begin__(s), __end__(s))` is always a valid range.
  88. * An __algorithm__ that iterates through the range `[__begin__(s), __end__(s))`
  89. will pass through every element of `s` exactly once.
  90. * `__begin__(s)` is identical to `__end__(s))` if and only if `s` is empty.
  91. * Two different iterations through `s` will access its elements in
  92. the same order.
  93. [heading Models]
  94. * __std_pair__
  95. * __boost_array__
  96. * __vector__
  97. * __cons__
  98. * __list__
  99. * __set__
  100. * __map__
  101. * __single_view__
  102. * __filter_view__
  103. * __iterator_range__
  104. * __joint_view__
  105. * __transform_view__
  106. * __reverse_view__
  107. * __zip_view__
  108. [endsect]
  109. [section Bidirectional Sequence]
  110. [heading Description]
  111. A Bidirectional Sequence is a __forward_sequence__ whose iterators model
  112. __bidirectional_iterator__.
  113. [heading Refinement of]
  114. __forward_sequence__
  115. [variablelist Notation
  116. [[`s`] [A Bidirectional Sequence]]
  117. [[`S`] [A Bidirectional Sequence type]]
  118. [[`o`] [An arbitrary object]]
  119. [[`e`] [A Sequence element]]
  120. ]
  121. [heading Valid Expressions]
  122. In addition to the requirements defined in __forward_sequence__, for any
  123. Bidirectional Sequence the following must be met:
  124. [table
  125. [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
  126. [[`__begin__(s)`] [__bidirectional_iterator__] [] [Constant]]
  127. [[`__end__(s)`] [__bidirectional_iterator__] [] [Constant]]
  128. [[`__back__(s)`] [Any type] [] [Constant]]
  129. [[`__back__(s) = o`] [Any type] [`s` is mutable and
  130. `e = o`, where `e`
  131. is the first element
  132. in the sequence, is
  133. a valid expression.] [Constant]]
  134. ]
  135. [heading Result Type Expressions]
  136. [table
  137. [[Expression] [Compile Time Complexity]]
  138. [[`__result_of_begin__<S>::type`] [Amortized constant time]]
  139. [[`__result_of_end__<S>::type`] [Amortized constant time]]
  140. [[`__result_of_back__<S>::type`] [Amortized constant time]]
  141. ]
  142. [heading Expression Semantics]
  143. The semantics of an expression are defined only where they differ from, or
  144. are not defined in __forward_sequence__.
  145. [table
  146. [[Expression] [Semantics]]
  147. [[`__back__(s)`] [The last element in the sequence; see __back__.]]
  148. ]
  149. [heading Models]
  150. * __std_pair__
  151. * __boost_array__
  152. * __vector__
  153. * __map__
  154. * __reverse_view__
  155. * __single_view__
  156. * __iterator_range__ (where adapted sequence is a Bidirectional Sequence)
  157. * __transform_view__ (where adapted sequence is a Bidirectional Sequence)
  158. * __zip_view__ (where adapted sequences are models of Bidirectional Sequence)
  159. [endsect]
  160. [section Random Access Sequence]
  161. [heading Description]
  162. A Random Access Sequence is a __bidirectional_sequence__ whose iterators
  163. model __random_access_iterator__. It guarantees constant time access to
  164. arbitrary sequence elements.
  165. [heading Refinement of]
  166. __bidirectional_sequence__
  167. [variablelist Notation
  168. [[`s`] [A Random Access Sequence]]
  169. [[`S`] [A Random Access Sequence type]]
  170. [[`M`] [An __mpl__ integral constant]]
  171. [[`N`] [An integral constant]]
  172. [[`o`] [An arbitrary object]]
  173. [[`e`] [A Sequence element]]
  174. ]
  175. [heading Valid Expressions]
  176. In addition to the requirements defined in __bidirectional_sequence__, for
  177. any Random Access Sequence the following must be met:
  178. [table
  179. [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
  180. [[`__begin__(s)`] [__random_access_iterator__] [] [Constant]]
  181. [[`__end__(s)`] [__random_access_iterator__] [] [Constant]]
  182. [[`__at_c__<N>(s)`] [Any type] [] [Constant]]
  183. [[`__at_c__<N>(s) = o`] [Any type] [`s` is mutable and
  184. `e = o`, where `e`
  185. is the first element
  186. in the sequence, is
  187. a valid expression.] [Constant]]
  188. [[`__at__<M>(s)`] [Any type] [] [Constant]]
  189. [[`__at__<M>(s) = o`] [Any type] [`s` is mutable and
  190. `e = o`, where `e`
  191. is the first element
  192. in the sequence, is
  193. a valid expression.] [Constant]]
  194. ]
  195. [heading Result Type Expressions]
  196. [table
  197. [[Expression] [Compile Time Complexity]]
  198. [[`__result_of_begin__<S>::type`] [Amortized constant time]]
  199. [[`__result_of_end__<S>::type`] [Amortized constant time]]
  200. [[`__result_of_at__<S, M>::type`] [Amortized constant time]]
  201. [[`__result_of_at_c__<S, N>::type`] [Amortized constant time]]
  202. [[`__result_of_value_at__<S, M>::type`] [Amortized constant time]]
  203. [[`__result_of_value_at_c__<S, N>::type`] [Amortized constant time]]
  204. ]
  205. [note `__result_of_at__<S, M>` returns the actual type returned by
  206. `__at__<M>(s)`. In most cases, this is a reference. Hence, there is no way to
  207. know the exact element type using `__result_of_at__<S, M>`.The element at `M`
  208. may actually be a reference to begin with. For this purpose, you can use
  209. `__result_of_value_at__<S, M>` (Note that, `__result_of_value_at_c__<S, N>`
  210. is a counterpart of `__result_of_at_c__<S, N>` as well).]
  211. [heading Expression Semantics]
  212. The semantics of an expression are defined only where they differ from, or
  213. are not defined in __bidirectional_sequence__.
  214. [table
  215. [[Expression] [Semantics]]
  216. [[`__at__<M>(s)`] [The Mth element from the beginning of the sequence; see __at__.]]
  217. [[`__at_c__<N>(s)`] [The Nth element from the beginning of the sequence; see __at_c__.]]
  218. ]
  219. [heading Models]
  220. * __std_pair__
  221. * __boost_array__
  222. * __vector__
  223. * __map__
  224. * __reverse_view__
  225. * __single_view__
  226. * __iterator_range__ (where adapted sequence is a Random Access Sequence)
  227. * __transform_view__ (where adapted sequence is a Random Access Sequence)
  228. * __zip_view__ (where adapted sequences are models of Random Access Sequence)
  229. [endsect]
  230. [section Associative Sequence]
  231. [heading Description]
  232. An Associative Sequence allows efficient retrieval of elements based on keys.
  233. Like associative sequences in __mpl__, and unlike associative containers in
  234. __stl__, Fusion associative sequences have no implied ordering relation.
  235. Instead, type identity is used to impose an equivalence relation on keys.
  236. Keys are not checked for uniqueness.
  237. [variablelist Notation
  238. [[`s`] [An Associative Sequence]]
  239. [[`S`] [An Associative Sequence type]]
  240. [[`K`] [An arbitrary /key/ type]]
  241. [[`o`] [An arbitrary object]]
  242. [[`e`] [A Sequence element]]
  243. ]
  244. [heading Valid Expressions]
  245. For any Associative Sequence the following expressions must be valid:
  246. [table
  247. [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
  248. [[`__has_key__<K>(s)`] [__mpl_boolean_constant__.
  249. Convertible to bool.] [] [Constant]]
  250. [[`__at_key__<K>(s)`] [Any type] [] [Constant]]
  251. [[`__at_key__<K>(s) = o`] [Any type] [`s` is mutable and
  252. `e = o`, where `e`
  253. is the first element
  254. in the sequence, is
  255. a valid expression.] [Constant]]
  256. ]
  257. [heading Result Type Expressions]
  258. [table
  259. [[Expression] [Compile Time Complexity]]
  260. [[`__result_of_has_key__<S, K>::type`] [Amortized constant time]]
  261. [[`__result_of_at_key__<S, K>::type`] [Amortized constant time]]
  262. [[`__result_of_value_at_key__<S, K>::type`] [Amortized constant time]]
  263. ]
  264. [note `__result_of_at_key__<S, K>` returns the actual type returned
  265. by `__at_key__<K>(s)`. In most cases, this is a reference. Hence, there is no
  266. way to know the exact element type using `__result_of_at_key__<S, K>`.The
  267. element at `K` may actually be a reference to begin with. For this purpose,
  268. you can use `__result_of_value_at_key__<S, K>`.]
  269. [heading Expression Semantics]
  270. [table
  271. [[Expression] [Semantics]]
  272. [[`__has_key__<K>(s)`] [A boolean Integral Constant `c` such that
  273. `c::value == true` if and only if there is
  274. one or more elements with the key `k` in `s`;
  275. see __has_key__.]]
  276. [[`__at_key__<K>(s)`] [The element associated with the key
  277. `K` in the sequence `s`; see __at__.]]
  278. ]
  279. [heading Models]
  280. * __set__
  281. * __map__
  282. * __filter_view__ (where adapted sequence is an __associative_sequence__ and a __forward_sequence__)
  283. * __iterator_range__ (where adapted iterators are __associative_iterator__\ s)
  284. * __joint_view__ (where adapted sequences are __associative_sequence__\ s and __forward_sequence__\ s)
  285. * __reverse_view__ (where adapted sequence is an __associative_sequence__ and a __bidirectional_sequence__)
  286. [endsect]
  287. [section Unbounded Sequence]
  288. [heading Description]
  289. A Unbounded Sequence allows Out-of-Bounds access: it will achieve something like a __window_function__.
  290. Most of the sequences do not meet this concept, but some special usecases do.
  291. [important User extending sequences should handle any parameters or be SFINAE-friendly.]
  292. [variablelist Notation
  293. [[`s`] [An Fusion Sequence]]
  294. [[`S`] [An Fusion Sequence type]]
  295. [[`M`] [An __mpl__ integral constant]]
  296. [[`N`] [An integral constant]]
  297. [[`K`] [An arbitrary /key/ type]]
  298. [[`o`] [An arbitrary object]]
  299. [[`e`] [A Sequence element]]
  300. ]
  301. [heading Valid Expressions]
  302. [table
  303. [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
  304. [[`__at_c__<N>(s)`] [Any type] [] [Depends on its traversability]]
  305. [[`__at_c__<N>(s) = o`] [Any type] [] [Depends on its traversability]]
  306. [[`__at__<M>(s)`] [Any type] [] [Depends on its traversability]]
  307. [[`__at__<M>(s) = o`] [Any type] [] [Depends on its traversability]]
  308. [[`__at_key__<K>(s)`] [Any type] [`S` should be __associative_sequence__] [Depends on its traversability]]
  309. [[`__at_key__<K>(s) = o`] [Any type] [`S` should be __associative_sequence__] [Depends on its traversability]]
  310. ]
  311. [heading Result Type Expressions]
  312. [table
  313. [[Expression] [Compile Time Complexity]]
  314. [[`__result_of_at__<S, M>::type`] [Depends on its traversability]]
  315. [[`__result_of_at_c__<S, N>::type`] [Depends on its traversability]]
  316. [[`__result_of_value_at__<S, M>::type`] [Depends on its traversability]]
  317. [[`__result_of_value_at_c__<S, N>::type`] [Depends on its traversability]]
  318. [[`__result_of_at_key__<S, K>::type`] [Depends on its traversability]]
  319. [[`__result_of_value_at_key__<S, K>::type`] [Depends on its traversability]]
  320. ]
  321. [heading Models]
  322. * none.
  323. [endsect]
  324. [endsect]
  325. [section Intrinsic]
  326. Intrinsic form the essential interface of every Fusion __sequence__. __stl__
  327. counterparts of these functions are usually implemented as member
  328. functions. Intrinsic functions, unlike __algorithms__, are not generic
  329. across the full __sequence__ repertoire. They need to be implemented for
  330. each Fusion __sequence__[footnote In practice, many of intrinsic functions
  331. have default implementations that will work in majority of cases].
  332. [heading Header]
  333. #include <boost/fusion/sequence/intrinsic.hpp>
  334. #include <boost/fusion/include/intrinsic.hpp>
  335. [section Functions]
  336. [section begin]
  337. [heading Description]
  338. Returns an iterator pointing to the first element in the sequence.
  339. [heading Synopsis]
  340. template <typename Sequence>
  341. typename __result_of_begin__<Sequence>::type
  342. begin(Sequence& seq);
  343. template <typename Sequence>
  344. typename __result_of_begin__<Sequence const>::type
  345. begin(Sequence const& seq);
  346. [heading Parameters]
  347. [table
  348. [[Parameter] [Requirement] [Description]]
  349. [[`seq`] [Model of __forward_sequence__] [The sequence we wish to get an iterator from.]]
  350. ]
  351. [heading Expression Semantics]
  352. begin(seq);
  353. [*Return type]:
  354. * A model of __forward_iterator__ if `seq` is a __forward_sequence__
  355. else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
  356. else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
  357. * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
  358. [*Semantics]: Returns an iterator pointing to the first element in the sequence.
  359. [heading Header]
  360. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  361. #include <boost/fusion/include/begin.hpp>
  362. [heading Example]
  363. __vector__<int, int, int> v(1, 2, 3);
  364. assert(__deref__(begin(v)) == 1);
  365. [endsect]
  366. [section end]
  367. [heading Description]
  368. Returns an iterator pointing to one element past the end of the sequence.
  369. [heading Synopsis]
  370. template <typename Sequence>
  371. typename __result_of_end__<Sequence>::type
  372. end(Sequence& seq);
  373. template <typename Sequence>
  374. typename __result_of_end__<Sequence const>::type
  375. end(Sequence const& seq);
  376. [heading Parameters]
  377. [table
  378. [[Parameter] [Requirement] [Description]]
  379. [[`seq`] [Model of __forward_sequence__] [The sequence we wish to get an iterator from.]]
  380. ]
  381. [heading Expression Semantics]
  382. end(seq);
  383. [*Return type]:
  384. * A model of __forward_iterator__ if `seq` is a __forward_sequence__
  385. else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
  386. else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
  387. * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
  388. [*Semantics]: Returns an iterator pointing to one element past the end of
  389. the sequence.
  390. [heading Header]
  391. #include <boost/fusion/sequence/intrinsic/end.hpp>
  392. #include <boost/fusion/include/end.hpp>
  393. [heading Example]
  394. __vector__<int, int, int> v(1, 2, 3);
  395. assert(__deref__(__prior__(end(v))) == 3);
  396. [endsect]
  397. [section empty]
  398. [heading Description]
  399. Returns a type convertible to `bool` that evaluates to `true` if the
  400. sequence is empty, else, evaluates to `false`.
  401. [heading Synopsis]
  402. template <typename Sequence>
  403. typename __result_of_empty__<Sequence>::type
  404. empty(Sequence const& seq);
  405. [heading Parameters]
  406. [table
  407. [[Parameter] [Requirement] [Description]]
  408. [[`seq`] [Model of __forward_sequence__] [The sequence we wish to investigate.]]
  409. ]
  410. [heading Expression Semantics]
  411. empty(seq);
  412. [*Return type]: Convertible to `bool`.
  413. [*Semantics]: Evaluates to `true` if the sequence is empty, else, evaluates
  414. to `false`.
  415. [heading Header]
  416. #include <boost/fusion/sequence/intrinsic/empty.hpp>
  417. #include <boost/fusion/include/empty.hpp>
  418. [heading Example]
  419. __vector__<int, int, int> v(1, 2, 3);
  420. assert(empty(v) == false);
  421. [endsect]
  422. [section front]
  423. [heading Description]
  424. Returns the first element in the sequence.
  425. [heading Synopsis]
  426. template <typename Sequence>
  427. typename __result_of_front__<Sequence>::type
  428. front(Sequence& seq);
  429. template <typename Sequence>
  430. typename __result_of_front__<Sequence const>::type
  431. front(Sequence const& seq);
  432. [heading Parameters]
  433. [table
  434. [[Parameter] [Requirement] [Description]]
  435. [[`seq`] [Model of __forward_sequence__] [The sequence we wish to investigate.]]
  436. ]
  437. [heading Expression Semantics]
  438. front(seq);
  439. [*Return type]: Returns a reference to the first element in the sequence
  440. `seq` if `seq` is mutable and `e = o`, where `e` is the first element in
  441. the sequence, is a valid expression. Else, returns a type convertible to
  442. the first element in the sequence.
  443. [*Precondition]: `__empty__(seq) == false`
  444. [*Semantics]: Returns the first element in the sequence.
  445. [heading Header]
  446. #include <boost/fusion/sequence/intrinsic/front.hpp>
  447. #include <boost/fusion/include/front.hpp>
  448. [heading Example]
  449. __vector__<int, int, int> v(1, 2, 3);
  450. assert(front(v) == 1);
  451. [endsect]
  452. [section back]
  453. [heading Description]
  454. Returns the last element in the sequence.
  455. [heading Synopsis]
  456. template <typename Sequence>
  457. typename __result_of_back__<Sequence>::type
  458. back(Sequence& seq);
  459. template <typename Sequence>
  460. typename __result_of_back__<Sequence const>::type
  461. back(Sequence const& seq);
  462. [heading Parameters]
  463. [table
  464. [[Parameter] [Requirement] [Description]]
  465. [[`seq`] [Model of __bidirectional_sequence__] [The sequence we wish to investigate.]]
  466. ]
  467. [heading Expression Semantics]
  468. back(seq);
  469. [*Return type]: Returns a reference to the last element in the sequence
  470. `seq` if `seq` is mutable and `e = o`, where `e` is the last element in the
  471. sequence, is a valid expression. Else, returns a type convertible to the
  472. last element in the sequence.
  473. [*Precondition]: `__empty__(seq) == false`
  474. [*Semantics]: Returns the last element in the sequence.
  475. [heading Header]
  476. #include <boost/fusion/sequence/intrinsic/back.hpp>
  477. #include <boost/fusion/include/back.hpp>
  478. [heading Example]
  479. __vector__<int, int, int> v(1, 2, 3);
  480. assert(back(v) == 3);
  481. [endsect]
  482. [section size]
  483. [heading Description]
  484. Returns a type convertible to `int` that evaluates the number of elements
  485. in the sequence.
  486. [heading Synopsis]
  487. template <typename Sequence>
  488. typename __result_of_size__<Sequence>::type
  489. size(Sequence const& seq);
  490. [heading Parameters]
  491. [table
  492. [[Parameter] [Requirement] [Description]]
  493. [[`seq`] [Model of __forward_sequence__] [The sequence we wish to investigate.]]
  494. ]
  495. [heading Expression Semantics]
  496. size(seq);
  497. [*Return type]: Convertible to `int`.
  498. [*Semantics]: Returns the number of elements in the sequence.
  499. [heading Header]
  500. #include <boost/fusion/sequence/intrinsic/size.hpp>
  501. #include <boost/fusion/include/size.hpp>
  502. [heading Example]
  503. __vector__<int, int, int> v(1, 2, 3);
  504. assert(size(v) == 3);
  505. [endsect]
  506. [section at]
  507. [heading Description]
  508. Returns the M-th element from the beginning of the sequence.
  509. [heading Synopsis]
  510. template <typename M, typename Sequence>
  511. typename __result_of_at__<Sequence, N>::type
  512. at(Sequence& seq);
  513. template <typename M, typename Sequence>
  514. typename __result_of_at__<Sequence const, N>::type
  515. at(Sequence const& seq);
  516. [heading Parameters]
  517. [table
  518. [[Parameter] [Requirement] [Description]]
  519. [[`seq`] [Model of __random_access_sequence__] [The sequence we wish to investigate.]]
  520. [[`M`] [An __mpl_integral_constant__] [An index from the beginning of the
  521. sequence.]]
  522. ]
  523. [heading Expression Semantics]
  524. at<M>(seq);
  525. [*Return type]: Returns a reference to the M-th element from the beginning
  526. of the sequence `seq` if `seq` is mutable and `e = o`, where `e` is the M-th
  527. element from the beginning of the sequence, is a valid expression. Else,
  528. returns a type convertible to the M-th element from the beginning of the
  529. sequence.
  530. [*Precondition]: `0 <= M::value < __size__(seq)` (where `seq` is not __unbounded_sequence__)
  531. [*Semantics]: Equivalent to
  532. __deref__(__advance__<M>(__begin__(s)))
  533. [heading Header]
  534. #include <boost/fusion/sequence/intrinsic/at.hpp>
  535. #include <boost/fusion/include/at.hpp>
  536. [heading Example]
  537. __vector__<int, int, int> v(1, 2, 3);
  538. assert(at<mpl::int_<1> >(v) == 2);
  539. [endsect]
  540. [section at_c]
  541. [heading Description]
  542. Returns the N-th element from the beginning of the sequence.
  543. [heading Synopsis]
  544. template <int N, typename Sequence>
  545. typename __result_of_at_c__<Sequence, N>::type
  546. at_c(Sequence& seq);
  547. template <int N, typename Sequence>
  548. typename __result_of_at_c__<Sequence const, N>::type
  549. at_c(Sequence const& seq);
  550. [heading Parameters]
  551. [table
  552. [[Parameter] [Requirement] [Description]]
  553. [[`seq`] [Model of __random_access_sequence__] [The sequence we wish to investigate.]]
  554. [[`N`] [An integral constant] [An index from the beginning of the
  555. sequence.]]
  556. ]
  557. [heading Expression Semantics]
  558. at_c<N>(seq);
  559. [*Return type]: Returns a reference to the N-th element from the beginning
  560. of the sequence `seq` if `seq` is mutable and `e = o`, where `e` is the N-th
  561. element from the beginning of the sequence, is a valid expression. Else,
  562. returns a type convertible to the N-th element from the beginning of the
  563. sequence.
  564. [*Precondition]: `0 <= N < __size__(seq)` (where `seq` is not __unbounded_sequence__)
  565. [*Semantics]: Equivalent to
  566. __deref__(__advance__<N>(__begin__(s)))
  567. [heading Header]
  568. #include <boost/fusion/sequence/intrinsic/at_c.hpp>
  569. #include <boost/fusion/include/at_c.hpp>
  570. [heading Example]
  571. __vector__<int, int, int> v(1, 2, 3);
  572. assert(at_c<1>(v) == 2);
  573. [endsect]
  574. [section has_key]
  575. [heading Description]
  576. Returns a type convertible to `bool` that evaluates to `true` if the
  577. sequence contains an element associated with a Key, else, evaluates to
  578. `false`.
  579. [heading Synopsis]
  580. template <typename Key, typename Sequence>
  581. typename __result_of_has_key__<Sequence, Key>::type
  582. has_key(Sequence const& seq);
  583. [heading Parameters]
  584. [table
  585. [[Parameter] [Requirement] [Description]]
  586. [[`seq`] [Model of __associative_sequence__] [The sequence we wish to investigate.]]
  587. [[`Key`] [Any type] [The queried key.]]
  588. ]
  589. [heading Expression Semantics]
  590. has_key<Key>(seq);
  591. [*Return type]: Convertible to `bool`.
  592. [*Semantics]: Evaluates to `true` if the sequence contains an element
  593. associated with Key, else, evaluates to `false`.
  594. [heading Header]
  595. #include <boost/fusion/sequence/intrinsic/has_key.hpp>
  596. #include <boost/fusion/include/has_key.hpp>
  597. [heading Example]
  598. __set__<int, char, bool> s(1, 'x', true);
  599. assert(has_key<char>(s) == true);
  600. [endsect]
  601. [section at_key]
  602. [heading Description]
  603. Returns the element associated with a Key from the sequence.
  604. [heading Synopsis]
  605. template <typename Key, typename Sequence>
  606. typename __result_of_at_key__<Sequence, Key>::type
  607. at_key(Sequence& seq);
  608. template <typename Key, typename Sequence>
  609. typename __result_of_at_key__<Sequence const, Key>::type
  610. at_key(Sequence const& seq);
  611. [heading Parameters]
  612. [table
  613. [[Parameter] [Requirement] [Description]]
  614. [[`seq`] [Model of __associative_sequence__] [The sequence we wish to investigate.]]
  615. [[`Key`] [Any type] [The queried key.]]
  616. ]
  617. [heading Expression Semantics]
  618. at_key<Key>(seq);
  619. [*Return type]: Returns a reference to the element associated with Key from
  620. the sequence `seq` if `seq` is mutable and `e = o`, where `e` is the
  621. element associated with Key, is a valid expression. Else, returns a type
  622. convertible to the element associated with Key.
  623. [*Precondition]: `has_key<Key>(seq) == true` (where `seq` is not __unbounded_sequence__)
  624. [*Semantics]: Returns the element associated with Key.
  625. [heading Header]
  626. #include <boost/fusion/sequence/intrinsic/at_key.hpp>
  627. #include <boost/fusion/include/at_key.hpp>
  628. [heading Example]
  629. __set__<int, char, bool> s(1, 'x', true);
  630. assert(at_key<char>(s) == 'x');
  631. [endsect]
  632. [section swap]
  633. [heading Description]
  634. Performs an element by element swap of the elements in 2 sequences.
  635. [heading Synopsis]
  636. template<typename Seq1, typename Seq2>
  637. typename __result_of_swap__<Seq1, Seq2>::type
  638. swap(Seq1& seq1, Seq2& seq2);
  639. [heading Parameters]
  640. [table
  641. [[Parameters] [Requirement] [Description]]
  642. [[`seq1`, `seq2`][Models of __forward_sequence__][The sequences whose elements we wish to swap.]]
  643. ]
  644. [heading Expression Semantics]
  645. swap(seq1, seq2);
  646. [*Return type]: `void`
  647. [*Precondition]: `__size__(seq1) == __size__(seq2)`
  648. [*Semantics]: Calls `swap(a1, b1)` for corresponding elements in `seq1` and `seq2`.
  649. [heading Header]
  650. #include <boost/fusion/sequence/intrinsic/swap.hpp>
  651. #include <boost/fusion/include/swap.hpp>
  652. [heading Example]
  653. __vector__<int, std::string> v1(1, "hello"), v2(2, "world");
  654. swap(v1, v2);
  655. assert(v1 == __make_vector__(2, "world"));
  656. assert(v2 == __make_vector__(1, "hello"));
  657. [endsect]
  658. [endsect]
  659. [section Metafunctions]
  660. [section begin]
  661. [heading Description]
  662. Returns the result type of __begin__.
  663. [heading Synopsis]
  664. template<typename Seq>
  665. struct begin
  666. {
  667. typedef __unspecified__ type;
  668. };
  669. [table Parameters
  670. [[Parameter] [Requirement] [Description]]
  671. [[`Seq`][A model of __forward_sequence__][Argument sequence]]
  672. ]
  673. [heading Expression Semantics]
  674. result_of::begin<Seq>::type
  675. [*Return type]:
  676. * A model of __forward_iterator__ if `seq` is a __forward_sequence__
  677. else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
  678. else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
  679. * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
  680. [*Semantics]: Returns the type of an iterator to the first element of `Seq`.
  681. [heading Header]
  682. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  683. #include <boost/fusion/include/begin.hpp>
  684. [heading Example]
  685. typedef __vector__<int> vec;
  686. typedef __result_of_begin__<vec>::type it;
  687. BOOST_MPL_ASSERT((boost::is_same<__result_of_deref__<it>::type, int&>))
  688. [endsect]
  689. [section end]
  690. [heading Description]
  691. Returns the result type of __end__.
  692. [heading Synopsis]
  693. template<typename Seq>
  694. struct end
  695. {
  696. typedef __unspecified__ type;
  697. };
  698. [table Parameters
  699. [[Parameter] [Requirement] [Description]]
  700. [[`Seq`][A model of __forward_sequence__][Argument sequence]]
  701. ]
  702. [heading Expression Semantics]
  703. result_of::end<Seq>::type
  704. [*Return type]:
  705. * A model of __forward_iterator__ if `seq` is a __forward_sequence__
  706. else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
  707. else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
  708. * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
  709. [*Semantics]: Returns the type of an iterator one past the end of `Seq`.
  710. [heading Header]
  711. #include <boost/fusion/sequence/intrinsic/end.hpp>
  712. #include <boost/fusion/include/end.hpp>
  713. [heading Example]
  714. typedef __vector__<int> vec;
  715. typedef __result_of_prior__<__result_of_end__<vec>::type>::type first;
  716. BOOST_MPL_ASSERT((__result_of_equal_to__<first, __result_of_begin__<vec>::type>))
  717. [endsect]
  718. [section empty]
  719. [heading Description]
  720. Returns the result type of __empty__.
  721. [heading Synopsis]
  722. template<typename Seq>
  723. struct empty
  724. {
  725. typedef __unspecified__ type;
  726. };
  727. [table Parameters
  728. [[Parameter] [Requirement] [Description]]
  729. [[`Seq`][A model of __forward_sequence__][Argument sequence]]
  730. ]
  731. [heading Expression Semantics]
  732. result_of::empty<Seq>::type
  733. [*Return type]: An __mpl_integral_constant__
  734. [*Semantics]: Returns `mpl::true_` if `Seq` has zero elements, `mpl::false_` otherwise.
  735. [heading Header]
  736. #include <boost/fusion/sequence/intrinsic/empty.hpp>
  737. #include <boost/fusion/include/empty.hpp>
  738. [heading Example]
  739. typedef __vector__<> empty_vec;
  740. typedef __vector__<int,float,char> vec;
  741. BOOST_MPL_ASSERT((__result_of_empty__<empty_vec>));
  742. BOOST_MPL_ASSERT_NOT((__result_of_empty__<vec>));
  743. [endsect]
  744. [section front]
  745. [heading Description]
  746. Returns the result type of __front__.
  747. [heading Synopsis]
  748. template<typename Seq>
  749. struct front
  750. {
  751. typedef __unspecified__ type;
  752. };
  753. [table Parameters
  754. [[Parameter] [Requirement] [Description]]
  755. [[`Seq`][A model of __forward_sequence__][Argument sequence]]
  756. ]
  757. [heading Expression Semantics]
  758. result_of::front<Seq>::type
  759. [*Return type]: Any type
  760. [*Semantics]: The type returned by dereferencing an iterator to the first element in `Seq`. Equivalent to `__result_of_deref__<__result_of_begin__<Seq>::type>::type`.
  761. [heading Header]
  762. #include <boost/fusion/sequence/intrinsic/front.hpp>
  763. #include <boost/fusion/include/front.hpp>
  764. [heading Example]
  765. typedef __vector__<int,char> vec;
  766. BOOST_MPL_ASSERT((boost::is_same<__result_of_front__<vec>::type, int&>));
  767. [endsect]
  768. [section back]
  769. [heading Description]
  770. Returns the result type of __back__.
  771. [heading Synopsis]
  772. template<typename Seq>
  773. struct back
  774. {
  775. typedef __unspecified__ type;
  776. };
  777. [table Parameters
  778. [[Parameter] [Requirement] [Description]]
  779. [[`Seq`][A model of __forward_sequence__][Argument sequence]]
  780. ]
  781. [heading Expression Semantics]
  782. result_of::back<Seq>::type
  783. [*Return type]: Any type
  784. [*Semantics]: The type returned by dereferencing an iterator to the last element in the sequence. Equivalent to `__result_of_deref__<__result_of_prior__<__result_of_end__<Seq>::type>::type>::type`.
  785. [heading Header]
  786. #include <boost/fusion/sequence/intrinsic/back.hpp>
  787. #include <boost/fusion/include/back.hpp>
  788. [heading Example]
  789. typedef __vector__<int,char> vec;
  790. BOOST_MPL_ASSERT((boost::is_same<__result_of_back__<vec>::type, char&>));
  791. [endsect]
  792. [section size]
  793. [heading Description]
  794. Returns the result type of __size__.
  795. [heading Synopsis]
  796. template<typename Seq>
  797. struct size
  798. {
  799. typedef __unspecified__ type;
  800. };
  801. [table Parameters
  802. [[Parameter] [Requirement] [Description]]
  803. [[`Seq`][A model of __forward_sequence__][Argument sequence]]
  804. ]
  805. [heading Expression Semantics]
  806. result_of::size<Seq>::type
  807. [*Return type]: An __mpl_integral_constant__.
  808. [*Semantics]: Returns the number of elements in `Seq`.
  809. [heading Header]
  810. #include <boost/fusion/sequence/intrinsic/size.hpp>
  811. #include <boost/fusion/include/size.hpp>
  812. [heading Example]
  813. typedef __vector__<int,float,char> vec;
  814. typedef __result_of_size__<vec>::type size_mpl_integral_constant;
  815. BOOST_MPL_ASSERT_RELATION(size_mpl_integral_constant::value, ==, 3);
  816. [endsect]
  817. [section at]
  818. [heading Description]
  819. Returns the result type of __at__[footnote __result_of_at__ reflects the
  820. actual return type of the function __at__. __sequence__(s) typically return
  821. references to its elements via the __at__ function. If you want to get
  822. the actual element type, use __result_of_value_at__].
  823. [heading Synopsis]
  824. template<
  825. typename Seq,
  826. typename M>
  827. struct at
  828. {
  829. typedef __unspecified__ type;
  830. };
  831. [table Parameters
  832. [[Parameter] [Requirement] [Description]]
  833. [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
  834. [[`M`][An __mpl_integral_constant__][Index of element]]
  835. ]
  836. [heading Expression Semantics]
  837. result_of::at<Seq, M>::type
  838. [*Return type]: Any type.
  839. [*Precondition]: `0 <= M::value < __result_of_size__<Seq>::value` (where `Seq` is not __unbounded_sequence__)
  840. [*Semantics]: Returns the result type of using __at__ to access the `M`th element of `Seq`.
  841. [heading Header]
  842. #include <boost/fusion/sequence/intrinsic/at.hpp>
  843. #include <boost/fusion/include/at.hpp>
  844. [heading Example]
  845. typedef __vector__<int,float,char> vec;
  846. BOOST_MPL_ASSERT((boost::is_same<__result_of_at__<vec, boost::mpl::int_<1> >::type, float&>));
  847. [endsect]
  848. [section at_c]
  849. [heading Description]
  850. Returns the result type of __at_c__[footnote __result_of_at_c__ reflects
  851. the actual return type of the function __at_c__. __sequence__(s) typically
  852. return references to its elements via the __at_c__ function. If you want to
  853. get the actual element type, use __result_of_value_at_c__].
  854. [heading Synopsis]
  855. template<
  856. typename Seq,
  857. int N>
  858. struct at_c
  859. {
  860. typedef __unspecified__ type;
  861. };
  862. [table Parameters
  863. [[Parameter] [Requirement] [Description]]
  864. [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
  865. [[`N`][Positive integer index][Index of element]]
  866. ]
  867. [heading Expression Semantics]
  868. result_of::at_c<Seq, N>::type
  869. [*Return type]: Any type
  870. [*Precondition]: `0 <= N < __result_of_size__<Seq>::value` (where `Seq` is not __unbounded_sequence__)
  871. [*Semantics]: Returns the result type of using __at_c__ to access the `N`th element of `Seq`.
  872. [heading Header]
  873. #include <boost/fusion/sequence/intrinsic/at.hpp>
  874. #include <boost/fusion/include/at.hpp>
  875. [heading Example]
  876. typedef __vector__<int,float,char> vec;
  877. BOOST_MPL_ASSERT((boost::is_same<__result_of_at_c__<vec, 1>::type, float&>));
  878. [endsect]
  879. [section value_at]
  880. [heading Description]
  881. Returns the actual type at a given index from the __sequence__.
  882. [heading Synopsis]
  883. template<
  884. typename Seq,
  885. typename M>
  886. struct value_at
  887. {
  888. typedef __unspecified__ type;
  889. };
  890. [table Parameters
  891. [[Parameter] [Requirement] [Description]]
  892. [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
  893. [[`M`][An __mpl_integral_constant__][Index of element]]
  894. ]
  895. [heading Expression Semantics]
  896. result_of::value_at<Seq, M>::type
  897. [*Return type]: Any type.
  898. [*Semantics]: Returns the actual type at the `M`th element of `Seq`.
  899. [heading Header]
  900. #include <boost/fusion/sequence/intrinsic/value_at.hpp>
  901. #include <boost/fusion/include/value_at.hpp>
  902. [heading Example]
  903. typedef __vector__<int,float,char> vec;
  904. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at__<vec, boost::mpl::int_<1> >::type, float>));
  905. [endsect]
  906. [section value_at_c]
  907. [heading Description]
  908. Returns the actual type at a given index from the __sequence__.
  909. [heading Synopsis]
  910. template<
  911. typename Seq,
  912. int N>
  913. struct value_at_c
  914. {
  915. typedef __unspecified__ type;
  916. };
  917. [table Parameters
  918. [[Parameter] [Requirement] [Description]]
  919. [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
  920. [[`N`][Positive integer index][Index of element]]
  921. ]
  922. [heading Expression Semantics]
  923. result_of::value_at_c<Seq, N>::type
  924. [*Return type]: Any type
  925. [*Semantics]: Returns the actual type at the `N`th element of `Seq`.
  926. [heading Header]
  927. #include <boost/fusion/sequence/intrinsic/value_at.hpp>
  928. #include <boost/fusion/include/value_at.hpp>
  929. [heading Example]
  930. typedef __vector__<int,float,char> vec;
  931. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at_c__<vec, 1>::type, float>));
  932. [endsect]
  933. [section has_key]
  934. [heading Description]
  935. Returns the result type of __has_key__.
  936. [heading Synopsis]
  937. template<
  938. typename Seq,
  939. typename Key>
  940. struct has_key
  941. {
  942. typedef __unspecified__ type;
  943. };
  944. [table Parameters
  945. [[Parameter] [Requirement] [Description]]
  946. [[`Seq`][A model of __associative_sequence__][Argument sequence]]
  947. [[`Key`][Any type][Key type]]
  948. ]
  949. [heading Expression Semantics]
  950. result_of::has_key<Seq, Key>::type
  951. [*Return type]: An __mpl_integral_constant__.
  952. [*Semantics]: Returns `mpl::true_` if `Seq` contains an element with key type `Key`, returns `mpl::false_` otherwise.
  953. [heading Header]
  954. #include <boost/fusion/sequence/intrinsic/has_key.hpp>
  955. #include <boost/fusion/include/has_key.hpp>
  956. [heading Example]
  957. typedef __map__<__pair__<int, char>, __pair__<char, char>, __pair__<double, char> > mymap;
  958. BOOST_MPL_ASSERT((__result_of_has_key__<mymap, int>));
  959. BOOST_MPL_ASSERT_NOT((__result_of_has_key__<mymap, void*>));
  960. [endsect]
  961. [section at_key]
  962. [heading Description]
  963. Returns the result type of __at_key__[footnote __result_of_at_key__
  964. reflects the actual return type of the function __at_key__. __sequence__(s)
  965. typically return references to its elements via the __at_key__ function. If
  966. you want to get the actual element type, use __result_of_value_at_key__].
  967. [heading Synopsis]
  968. template<
  969. typename Seq,
  970. typename Key>
  971. struct at_key
  972. {
  973. typedef __unspecified__ type;
  974. };
  975. [table Parameters
  976. [[Parameter] [Requirement] [Description]]
  977. [[`Seq`][A model of __associative_sequence__][Argument sequence]]
  978. [[`Key`][Any type][Key type]]
  979. ]
  980. [heading Expression Semantics]
  981. result_of::at_key<Seq, Key>::type
  982. [*Return type]: Any type.
  983. [*Precondition]: `has_key<Seq, Key>::type::value == true` (where `Seq` is not __unbounded_sequence__)
  984. [*Semantics]: Returns the result of using __at_key__ to access the element with key type `Key` in `Seq`.
  985. [heading Header]
  986. #include <boost/fusion/sequence/intrinsic/at_key.hpp>
  987. #include <boost/fusion/include/at_key.hpp>
  988. [heading Example]
  989. typedef __map__<__pair__<int, char>, __pair__<char, char>, __pair__<double, char> > mymap;
  990. BOOST_MPL_ASSERT((boost::is_same<__result_of_at_key__<mymap, int>::type, char&>));
  991. [endsect]
  992. [section value_at_key]
  993. [heading Description]
  994. Returns the actual element type associated with a Key from the __sequence__.
  995. [heading Synopsis]
  996. template<
  997. typename Seq,
  998. typename Key>
  999. struct value_at_key
  1000. {
  1001. typedef __unspecified__ type;
  1002. };
  1003. [table Parameters
  1004. [[Parameter] [Requirement] [Description]]
  1005. [[`Seq`][A model of __associative_sequence__][Argument sequence]]
  1006. [[`Key`][Any type][Key type]]
  1007. ]
  1008. [heading Expression Semantics]
  1009. result_of::value_at_key<Seq, Key>::type
  1010. [*Return type]: Any type.
  1011. [*Precondition]: `has_key<Seq, Key>::type::value == true` (where `Seq` is not __unbounded_sequence__)
  1012. [*Semantics]: Returns the actual element type associated with key type
  1013. `Key` in `Seq`.
  1014. [heading Header]
  1015. #include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
  1016. #include <boost/fusion/include/value_at_key.hpp>
  1017. [heading Example]
  1018. typedef __map__<__pair__<int, char>, __pair__<char, char>, __pair__<double, char> > mymap;
  1019. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at_key__<mymap, int>::type, char>));
  1020. [endsect]
  1021. [section swap]
  1022. [heading Description]
  1023. Returns the return type of swap.
  1024. [heading Synopsis]
  1025. template<typename Seq1, typename Seq2>
  1026. struct swap
  1027. {
  1028. typedef void type;
  1029. };
  1030. [table Parameters
  1031. [[Parameters] [Requirement] [Description]]
  1032. [[`Seq1`, `Seq2`][Models of __forward_sequence__][The sequences being swapped]]
  1033. ]
  1034. [heading Expression Semantics]
  1035. result_of::swap<Seq1, Seq2>::type
  1036. [*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence.
  1037. Otherwise, none.
  1038. [*Semantics]: Returns the return type of __swap__ for 2 sequences of types `Seq1` and `Seq2`.
  1039. [heading Header]
  1040. #include <boost/fusion/sequence/intrinsic/swap.hpp>
  1041. #include <boost/fusion/include/swap.hpp>
  1042. [endsect]
  1043. [endsect]
  1044. [endsect]
  1045. [section Operator]
  1046. These operators, like the __algorithms__, work generically on all Fusion
  1047. sequences. All conforming Fusion sequences automatically get these
  1048. operators for free.
  1049. [section I/O]
  1050. The I/O operators: `<<` and `>>` work generically on all Fusion
  1051. sequences. The I/O operators are overloaded in namespace `boost::fusion`
  1052. [footnote __sequence__(s) and __views__ residing in different namespaces
  1053. will have to either provide their own I/O operators (possibly forwarding
  1054. to fusion's I/O operators) or hoist fusion's I/O operators (using
  1055. declaration), in their own namespaces for proper argument dependent
  1056. lookup.]
  1057. The `operator<<` has been overloaded for generic output streams such
  1058. that __sequence__(s) are output by recursively calling `operator<<` for
  1059. each element. Analogously, the global `operator>>` has been overloaded
  1060. to extract __sequence__(s) from generic input streams by recursively
  1061. calling `operator>>` for each element.
  1062. Please note that, to display your adapted types via fusion IO system,
  1063. corresponding overloaded operators should be introduced to same namespace
  1064. of the type.
  1065. namespace your_awesome_library
  1066. {
  1067. using boost::fusion::operators::operator>>; // for input
  1068. using boost::fusion::operators::operator<<; // for output
  1069. ...
  1070. The default delimiter between the elements is space, and the __sequence__
  1071. is enclosed in parenthesis. For Example:
  1072. __vector__<float, int, std::string> a(1.0f, 2, std::string("Howdy folks!");
  1073. cout << a;
  1074. outputs the __vector__ as: (1.0 2 Howdy folks!)
  1075. The library defines three manipulators for changing the default behavior:
  1076. [variablelist Manipulators
  1077. [[`tuple_open(arg)`] [Defines the character that is output before the first element.]]
  1078. [[`tuple_close(arg)`] [Defines the character that is output after the last element.]]
  1079. [[`tuple_delimiter(arg)`] [Defines the delimiter character between elements.]]
  1080. ]
  1081. The argument to `tuple_open`, `tuple_close` and `tuple_delimiter` may be a
  1082. `char`, `wchar_t`, a C-string, or a wide C-string.
  1083. Example:
  1084. std::cout << tuple_open('[') << tuple_close(']') << tuple_delimiter(", ") << a;
  1085. outputs the same __vector__, `a` as: [1.0, 2, Howdy folks!]
  1086. The same manipulators work with `operator>>` and `istream` as well. Suppose
  1087. the `std::cin` stream contains the following data:
  1088. (1 2 3) [4:5]
  1089. The code:
  1090. __vector__<int, int, int> i;
  1091. __vector__<int, int> j;
  1092. std::cin >> i;
  1093. std::cin >> tuple_open('[') >> tuple_close(']') >> tuple_delimiter(':');
  1094. std::cin >> j;
  1095. reads the data into the __vector__(s) `i` and `j`.
  1096. Note that extracting __sequence__(s) with `std::string` or C-style string
  1097. elements does not generally work, since the streamed __sequence__
  1098. representation may not be unambiguously parseable.
  1099. [heading Header]
  1100. #include <boost/fusion/sequence/io.hpp>
  1101. #include <boost/fusion/include/io.hpp>
  1102. [section in]
  1103. [heading Description]
  1104. Read a __sequence__ from an input stream.
  1105. [heading Synopsis]
  1106. template <typename IStream, typename Sequence>
  1107. IStream&
  1108. operator>>(IStream& is, Sequence& seq);
  1109. [heading Parameters]
  1110. [table
  1111. [[Parameter] [Requirement] [Description]]
  1112. [[is] [An input stream.] [Stream to extract information from.]]
  1113. [[seq] [A __sequence__.] [The sequence to read.]]
  1114. ]
  1115. [heading Expression Semantics]
  1116. is >> seq
  1117. [*Return type]: IStream&
  1118. [*Semantics]: For each element, `e`, in sequence, `seq`, call `is >> e`.
  1119. [heading Header]
  1120. #include <boost/fusion/sequence/io/in.hpp>
  1121. #include <boost/fusion/include/in.hpp>
  1122. [heading Example]
  1123. __vector__<int, std::string, char> v;
  1124. std::cin >> v;
  1125. [endsect]
  1126. [section out]
  1127. [heading Description]
  1128. Write a __sequence__ to an output stream.
  1129. [heading Synopsis]
  1130. template <typename OStream, typename Sequence>
  1131. OStream&
  1132. operator<<(OStream& os, Sequence& seq);
  1133. [heading Parameters]
  1134. [table
  1135. [[Parameter] [Requirement] [Description]]
  1136. [[os] [An output stream.] [Stream to write information to.]]
  1137. [[seq] [A __sequence__.] [The sequence to write.]]
  1138. ]
  1139. [heading Expression Semantics]
  1140. os << seq
  1141. [*Return type]: OStream&
  1142. [*Semantics]: For each element, `e`, in sequence, `seq`, call `os << e`.
  1143. [heading Header]
  1144. #include <boost/fusion/sequence/io/out.hpp>
  1145. #include <boost/fusion/include/out.hpp>
  1146. [heading Example]
  1147. std::cout << __make_vector__(123, "Hello", 'x') << std::endl;
  1148. [endsect]
  1149. [endsect]
  1150. [section Comparison]
  1151. The Comparison operators: `==`, `!=`, `<`, `<=`, `>=` and `>=` work
  1152. generically on all Fusion sequences. Comparison operators are "short-
  1153. circuited": elementary comparisons start from the first elements and are
  1154. performed only until the result is clear.
  1155. [heading Header]
  1156. #include <boost/fusion/sequence/comparison.hpp>
  1157. #include <boost/fusion/include/comparison.hpp>
  1158. [section equal]
  1159. [heading Description]
  1160. Compare two sequences for equality.
  1161. [heading Synopsis]
  1162. template <typename Seq1, typename Seq2>
  1163. bool
  1164. operator==(Seq1 const& a, Seq2 const& b);
  1165. [heading Parameters]
  1166. [table
  1167. [[Parameter] [Requirement] [Description]]
  1168. [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
  1169. ]
  1170. [heading Expression Semantics]
  1171. a == b
  1172. [*Return type]: `bool`
  1173. [*Requirements]:
  1174. For each element, `e1`, in sequence `a`, and for each element, `e2`, in
  1175. sequence `b`, `a == b` is a valid expression returning a type that is
  1176. convertible to bool.
  1177. An attempt to compare two Sequences of different lengths results in a
  1178. compile time error.
  1179. [*Semantics]:
  1180. For each element, `e1`, in sequence `a`, and for each element, `e2`, in
  1181. sequence `b`, `e1 == e2` returns true. For any 2 zero length __sequence__(s),
  1182. e and f, e == f returns true.
  1183. [heading Header]
  1184. #include <boost/fusion/sequence/comparison/equal_to.hpp>
  1185. #include <boost/fusion/include/equal_to.hpp>
  1186. [heading Example]
  1187. __vector__<int, char> v1(5, 'a');
  1188. __vector__<int, char> v2(5, 'a');
  1189. assert(v1 == v2);
  1190. [endsect]
  1191. [section not equal]
  1192. Compare two sequences for inequality.
  1193. [heading Synopsis]
  1194. template <typename Seq1, typename Seq2>
  1195. bool
  1196. operator!=(Seq1 const& a, Seq2 const& b);
  1197. [heading Parameters]
  1198. [table
  1199. [[Parameter] [Requirement] [Description]]
  1200. [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
  1201. ]
  1202. [heading Expression Semantics]
  1203. a != b
  1204. [*Return type]: `bool`
  1205. [*Requirements]:
  1206. For each element, `e1`, in sequence `a`, and for each element, `e2`, in
  1207. sequence `b`, `a == b` is a valid expression returning a type that is
  1208. convertible to bool.
  1209. An attempt to compare two Sequences of different lengths results in a
  1210. compile time error.
  1211. [*Semantics]:
  1212. Returns !(a == b).
  1213. [heading Header]
  1214. #include <boost/fusion/sequence/comparison/not_equal_to.hpp>
  1215. #include <boost/fusion/include/not_equal_to.hpp>
  1216. [heading Example]
  1217. __vector__<int, char> v3(5, 'b');
  1218. __vector__<int, char> t4(2, 'a');
  1219. assert(v1 != v3);
  1220. assert(v1 != t4);
  1221. assert(!(v1 != v2));
  1222. [endsect]
  1223. [section less than]
  1224. Lexicographically compare two sequences.
  1225. [heading Synopsis]
  1226. template <typename Seq1, typename Seq2>
  1227. bool
  1228. operator<(Seq1 const& a, Seq2 const& b);
  1229. [heading Parameters]
  1230. [table
  1231. [[Parameter] [Requirement] [Description]]
  1232. [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
  1233. ]
  1234. [heading Expression Semantics]
  1235. a < b
  1236. [*Return type]: `bool`
  1237. [*Requirements]:
  1238. For each element, `e1`, in sequence `a`, and for each element, `e2`, in
  1239. sequence `b`, `a < b` is a valid expression returning a type that is
  1240. convertible to bool.
  1241. An attempt to compare two Sequences of different lengths results in a
  1242. compile time error.
  1243. [*Semantics]: Returns the lexicographical comparison of between `a` and `b`.
  1244. [heading Header]
  1245. #include <boost/fusion/sequence/comparison/less.hpp>
  1246. #include <boost/fusion/include/less.hpp>
  1247. [heading Example]
  1248. __vector__<int, float> v1(4, 3.3f);
  1249. __vector__<short, float> v2(5, 3.3f);
  1250. __vector__<long, double> v3(5, 4.4);
  1251. assert(v1 < v2);
  1252. assert(v2 < v3);
  1253. [endsect]
  1254. [section less than equal]
  1255. Lexicographically compare two sequences.
  1256. [heading Synopsis]
  1257. template <typename Seq1, typename Seq2>
  1258. bool
  1259. operator<=(Seq1 const& a, Seq2 const& b);
  1260. [heading Parameters]
  1261. [table
  1262. [[Parameter] [Requirement] [Description]]
  1263. [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
  1264. ]
  1265. [heading Expression Semantics]
  1266. a <= b
  1267. [*Return type]: `bool`
  1268. [*Requirements]:
  1269. For each element, `e1`, in sequence `a`, and for each element, `e2`, in
  1270. sequence `b`, `a < b` is a valid expression returning a type that is
  1271. convertible to bool.
  1272. An attempt to compare two Sequences of different lengths results in a
  1273. compile time error.
  1274. [*Semantics]: Returns !(b < a).
  1275. [heading Header]
  1276. #include <boost/fusion/sequence/comparison/less_equal.hpp>
  1277. #include <boost/fusion/include/less_equal.hpp>
  1278. [heading Example]
  1279. __vector__<int, float> v1(4, 3.3f);
  1280. __vector__<short, float> v2(5, 3.3f);
  1281. __vector__<long, double> v3(5, 4.4);
  1282. assert(v1 <= v2);
  1283. assert(v2 <= v3);
  1284. [endsect]
  1285. [section greater than]
  1286. Lexicographically compare two sequences.
  1287. [heading Synopsis]
  1288. template <typename Seq1, typename Seq2>
  1289. bool
  1290. operator>(Seq1 const& a, Seq2 const& b);
  1291. [heading Parameters]
  1292. [table
  1293. [[Parameter] [Requirement] [Description]]
  1294. [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
  1295. ]
  1296. [heading Expression Semantics]
  1297. a > b
  1298. [*Return type]: `bool`
  1299. [*Requirements]:
  1300. For each element, `e1`, in sequence `a`, and for each element, `e2`, in
  1301. sequence `b`, `a < b` is a valid expression returning a type that is
  1302. convertible to bool.
  1303. An attempt to compare two Sequences of different lengths results in a
  1304. compile time error.
  1305. [*Semantics]: Returns b < a.
  1306. [heading Header]
  1307. #include <boost/fusion/sequence/comparison/less_equal.hpp>
  1308. #include <boost/fusion/include/less_equal.hpp>
  1309. [heading Example]
  1310. __vector__<int, float> v1(4, 3.3f);
  1311. __vector__<short, float> v2(5, 3.3f);
  1312. __vector__<long, double> v3(5, 4.4);
  1313. assert(v2 > v1);
  1314. assert(v3 > v2);
  1315. [endsect]
  1316. [section greater than equal]
  1317. Lexicographically compare two sequences.
  1318. [heading Synopsis]
  1319. template <typename Seq1, typename Seq2>
  1320. bool
  1321. operator>=(Seq1 const& a, Seq2 const& b);
  1322. [heading Parameters]
  1323. [table
  1324. [[Parameter] [Requirement] [Description]]
  1325. [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
  1326. ]
  1327. [heading Expression Semantics]
  1328. a >= b
  1329. [*Return type]: `bool`
  1330. [*Requirements]:
  1331. For each element, `e1`, in sequence `a`, and for each element, `e2`, in
  1332. sequence `b`, `a < b` is a valid expression returning a type that is
  1333. convertible to bool.
  1334. An attempt to compare two Sequences of different lengths results in a
  1335. compile time error.
  1336. [*Semantics]: Returns !(a < b).
  1337. [heading Header]
  1338. #include <boost/fusion/sequence/comparison/greater_equal.hpp>
  1339. #include <boost/fusion/include/greater_equal.hpp>
  1340. [heading Example]
  1341. __vector__<int, float> v1(4, 3.3f);
  1342. __vector__<short, float> v2(5, 3.3f);
  1343. __vector__<long, double> v3(5, 4.4);
  1344. assert(v2 >= v1);
  1345. assert(v3 >= v2);
  1346. [endsect]
  1347. [endsect]
  1348. [section Hashing]
  1349. Automatically create a `boost::hash` conforming `hash_value` function.
  1350. [heading Synopsis]
  1351. template <typename Seq>
  1352. std::size_t
  1353. hash_value(Seq const& seq);
  1354. [heading Parameters]
  1355. [table
  1356. [[Parameter] [Requirement] [Description]]
  1357. [[`seq`] [Instance of __sequence__] [__sequence__ to compute hash value of]]
  1358. ]
  1359. [*Return type]: `std::size_t`
  1360. [*Requirements]:
  1361. For each element `e` in sequence `seq`, `hash_value(seq)` is a valid expression
  1362. returning a type that is convertible to `std::size_t`.
  1363. [*Semantics]: Returns a combined hash value for all elements of `seq`.
  1364. [heading Header]
  1365. #include <boost/fusion/sequence/hash.hpp>
  1366. #include <boost/fusion/include/hash.hpp>
  1367. [heading Example]
  1368. #include <boost/fusion/include/equal_to.hpp>
  1369. #include <boost/fusion/include/hash.hpp>
  1370. #include <boost/fusion/include/vector.hpp>
  1371. #include <boost/unordered_map.hpp>
  1372. void foo()
  1373. {
  1374. typedef boost::fusion::vector<int, std::string, char> Vec;
  1375. const Vec v = {42, "Hello World", 't'};
  1376. // Compute a hash value directly.
  1377. std::cout << "hash_value(v) = " << boost::fusion::hash_value(v) << '\n';
  1378. // Or use it to create an unordered_map.
  1379. boost::unordered_map<Vec, bool> map;
  1380. map[v] = true;
  1381. assert(map.size() == 1 && map.count(v) == 1);
  1382. }
  1383. [heading Example]
  1384. #include <boost/fusion/include/define_struct.hpp>
  1385. #include <boost/fusion/include/equal_to.hpp>
  1386. #include <boost/fusion/include/hash.hpp>
  1387. #include <boost/unordered_set.hpp>
  1388. // We would like to define a struct that we can form unordered_sets of.
  1389. BOOST_FUSION_DEFINE_STRUCT(
  1390. (demo), Key,
  1391. (bool, b)
  1392. (std::string, s)
  1393. (int, i)
  1394. )
  1395. namespace demo {
  1396. // Make operator== and hash_value ADL accessible.
  1397. using boost::fusion::operator==;
  1398. using boost::fusion::hash_value;
  1399. typedef boost::unordered_set<demo::Key> Set;
  1400. }
  1401. void foo()
  1402. {
  1403. demo::Set set;
  1404. demo::Key key;
  1405. assert(set.count(key) == 0);
  1406. }
  1407. [heading See also]
  1408. __boost_func_hash__
  1409. [endsect]
  1410. [endsect]
  1411. [endsect]