iterator.qbk 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2006 Dan Marsden
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. ===============================================================================/]
  8. [section Iterator]
  9. Like __mpl__ and __stl__, iterators are a fundamental concept in Fusion.
  10. As with __mpl__ and __stl__ iterators describe positions, and
  11. provide access to data within an underlying __sequence__.
  12. [heading Header]
  13. #include <boost/fusion/iterator.hpp>
  14. #include <boost/fusion/include/iterator.hpp>
  15. [section Concepts]
  16. Fusion iterators are divided into different traversal categories.
  17. __forward_iterator__ is the most basic concept. __bidirectional_iterator__
  18. is a refinement of __forward_iterator__. __random_access_iterator__ is a
  19. refinement of __bidirectional_iterator__. __associative_iterator__ is a
  20. refinement of __forward_iterator__, __bidirectional_iterator__ or
  21. __random_access_iterator__.
  22. [section Forward Iterator]
  23. [heading Description]
  24. A Forward Iterator traverses a __sequence__ allowing movement in only one direction through
  25. it's elements, one element at a time.
  26. [variablelist Notation
  27. [[`i`, `j`] [Forward Iterators]]
  28. [[`I`, `J`] [Forward Iterator types]]
  29. [[`M`] [An __mpl__ integral constant]]
  30. [[`N`] [An integral constant]]
  31. ]
  32. [heading Expression requirements]
  33. A type models Forward Iterator if, in addition to being CopyConstructable,
  34. the following expressions are valid:
  35. [table
  36. [[Expression] [Return type] [Runtime Complexity]]
  37. [[`__next__(i)`] [__forward_iterator__] [Constant]]
  38. [[`i == j`] [Convertible to bool] [Constant]]
  39. [[`i != j`] [Convertible to bool] [Constant]]
  40. [[`__advance_c__<N>(i)`] [__forward_iterator__] [Constant]]
  41. [[`__advance__<M>(i)`] [__forward_iterator__] [Constant]]
  42. [[`__distance__(i, j)`] [`__result_of_distance__<I, J>::type`][Constant]]
  43. [[`__deref__(i)`] [`__result_of_deref__<I>::type`] [Constant]]
  44. [[`*i`] [`__result_of_deref__<I>::type`] [Constant]]
  45. ]
  46. [heading Meta Expressions]
  47. [table
  48. [[Expression] [Compile Time Complexity]]
  49. [[`__result_of_next__<I>::type`] [Amortized constant time]]
  50. [[`__result_of_equal_to__<I, J>::type`] [Amortized constant time]]
  51. [[`__result_of_advance_c__<I, N>::type`] [Linear]]
  52. [[`__result_of_advance__<I ,M>::type`] [Linear]]
  53. [[`__result_of_distance__<I ,J>::type`] [Linear]]
  54. [[`__result_of_deref__<I>::type`] [Amortized constant time]]
  55. [[`__result_of_value_of__<I>::type`] [Amortized constant time]]
  56. ]
  57. [heading Expression Semantics]
  58. [table
  59. [[Expression] [Semantics]]
  60. [[`__next__(i)`] [An iterator to the element following `i`]]
  61. [[`i == j`] [Iterator equality comparison]]
  62. [[`i != j`] [Iterator inequality comparison]]
  63. [[`__advance_c__<N>(i)`] [An iterator n elements after `i` in the sequence]]
  64. [[`__advance__<M>(i)`] [Equivalent to `advance_c<M::value>(i)`]]
  65. [[`__distance__(i, j)`] [The number of elements between `i` and `j`]]
  66. [[`__deref__(i)`] [The element at position`i`]]
  67. [[`*i`] [Equivalent to `deref(i)`]]
  68. ]
  69. [heading Invariants]
  70. The following invariants always hold:
  71. * `!(i == j) == (i != j)`
  72. * `__next__(i) == __advance_c__<1>(i)`
  73. * `__distance__(i, __advance_c__<N>(i)) == N`
  74. * Using `__next__` to traverse the sequence will never return to a previously seen position
  75. * `__deref__(i)` is equivalent to `*i`
  76. * If `i == j` then `*i` is equivalent to `*j`
  77. [heading Models]
  78. * __std_pair__ iterator
  79. * __boost_array__ iterator
  80. * __vector__ iterator
  81. * __cons__ iterator
  82. * __list__ iterator
  83. * __set__ iterator
  84. * __map__ iterator
  85. * __single_view__ iterator
  86. * __filter_view__ iterator
  87. * __iterator_range__ iterator
  88. * __joint_view__ iterator
  89. * __transform_view__ iterator
  90. * __reverse_view__ iterator
  91. [endsect]
  92. [section Bidirectional Iterator]
  93. [heading Description]
  94. A Bidirectional Iterator traverses a __sequence__ allowing movement in either direction one
  95. element at a time.
  96. [variablelist Notation
  97. [[`i`] [A Bidirectional Iterator]]
  98. [[`I`] [A Bidirectional Iterator type]]
  99. [[`M`] [An __mpl__ integral constant]]
  100. [[`N`] [An integral constant]]
  101. ]
  102. [heading Refinement of]
  103. __forward_iterator__
  104. [heading Expression requirements]
  105. In addition to the requirements defined in __forward_iterator__,
  106. the following expressions must be valid:
  107. [table
  108. [[Expression] [Return type] [Runtime Complexity]]
  109. [[`__next__(i)`] [__bidirectional_iterator__] [Constant]]
  110. [[`__prior__(i)`] [__bidirectional_iterator__] [Constant]]
  111. [[`__advance_c__<N>(i)`] [__bidirectional_iterator__] [Constant]]
  112. [[`__advance__<M>(i)`] [__bidirectional_iterator__] [Constant]]
  113. ]
  114. [heading Meta Expressions]
  115. [table
  116. [[Expression] [Compile Time Complexity]]
  117. [[`__result_of_prior__<I>::type`] [Amortized constant time]]
  118. ]
  119. [heading Expression Semantics]
  120. The semantics of an expression are defined only where they differ from, or are not defined
  121. in __forward_iterator__
  122. [table
  123. [[Expression] [Semantics]]
  124. [[`__prior__(i)`] [An iterator to the element preceding `i`]]
  125. ]
  126. [heading Invariants]
  127. In addition to the invariants of __forward_iterator__,
  128. the following invariants always hold:
  129. * `__prior__(__next__(i)) == i && __prior__(__next__(i)) == __next__(__prior__(i))`
  130. * `__prior__(i) == __advance_c__<-1>(i)`
  131. * Using `__prior__` to traverse a sequence will never return a previously seen position
  132. [heading Models]
  133. * __std_pair__ iterator
  134. * __boost_array__ iterator
  135. * __vector__ iterator
  136. * __map__ iterator
  137. * __single_view__ iterator
  138. * __iterator_range__ (where adapted sequence is a __bidirectional_sequence__)
  139. * __transform_view__ (where adapted sequence is a __bidirectional_sequence__)
  140. * __reverse_view__
  141. [endsect]
  142. [section Random Access Iterator]
  143. [heading Description]
  144. A Random Access Iterator traverses a __sequence__ moving in either direction,
  145. permitting efficient arbitrary distance movements back and forward through the
  146. sequence.
  147. [variablelist Notation
  148. [[`i`, `j`] [Random Access Iterators]]
  149. [[`I`, `J`] [Random Access Iterator types]]
  150. [[`M`] [An __mpl__ integral constant]]
  151. [[`N`] [An integral constant]]
  152. ]
  153. [heading Refinement of]
  154. __bidirectional_iterator__
  155. [heading Expression requirements]
  156. In addition to the requirements defined in __bidirectional_iterator__,
  157. the following expressions must be valid:
  158. [table
  159. [[Expression] [Return type] [Runtime Complexity]]
  160. [[`__next__(i)`] [__random_access_iterator__] [Constant]]
  161. [[`__prior__(i)`] [__random_access_iterator__] [Constant]]
  162. [[`__advance_c__<N>(i)`] [__random_access_iterator__] [Constant]]
  163. [[`__advance__<M>(i)`] [__random_access_iterator__] [Constant]]
  164. ]
  165. [heading Meta Expressions]
  166. [table
  167. [[Expression] [Compile Time Complexity]]
  168. [[`__result_of_advance_c__<I, N>::type`] [Amortized constant time]]
  169. [[`__result_of_advance__<I, M>::type`] [Amortized constant time]]
  170. [[`__result_of_distance__<I ,J>::type`] [Amortized constant time]]
  171. ]
  172. [heading Models]
  173. * __vector__ iterator
  174. * __map__ iterator
  175. * __std_pair__ iterator
  176. * __boost_array__ iterator
  177. * __single_view__ iterator
  178. * __iterator_range__ iterator (where adapted sequence is a __random_access_sequence__)
  179. * __transform_view__ iterator (where adapted sequence is a __random_access_sequence__)
  180. * __reverse_view__ iterator (where adapted sequence is a __random_access_sequence__)
  181. [endsect]
  182. [section Associative Iterator]
  183. [heading Description]
  184. An Associative Iterator provides additional semantics to obtain the properties
  185. of the element of an associative forward, bidirectional or random access sequence.
  186. [variablelist Notation
  187. [[`i`] [Associative Iterator]]
  188. [[`I`] [Associative Iterator type]]
  189. ]
  190. [heading Refinement of]
  191. __forward_iterator__, __bidirectional_iterator__ or __random_access_iterator__
  192. [heading Expression requirements]
  193. In addition to the requirements defined in __forward_iterator__,
  194. __bidirectional_iterator__ or __random_access_iterator__ the following
  195. expressions must be valid:
  196. [table
  197. [[Expression] [Return type] [Runtime Complexity]]
  198. [[`__deref_data__(i)`][`__result_of_deref_data__<I>::type`][Constant]]
  199. ]
  200. [heading Meta Expressions]
  201. [table
  202. [[Expression] [Compile Time Complexity]]
  203. [[`__result_of_key_of__<I>::type`][Amortized constant time]]
  204. [[`__result_of_value_of_data__<I>::type`][Amortized constant time]]
  205. [[`__result_of_deref_data__<I>::type`][Amortized constant time]]
  206. ]
  207. [heading Models]
  208. * __map__ iterator
  209. * __set__ iterator
  210. * __filter_view__ iterator (where adapted sequence is an __associative_sequence__ and a __forward_sequence__)
  211. * __iterator_range__ iterator (where adapted iterators are __associative_iterator__\ s)
  212. * __joint_view__ iterator (where adapted sequences are __associative_sequence__\ s and __forward_sequence__\ s)
  213. * __reverse_view__ iterator (where adapted sequence is an __associative_sequence__ and a __bidirectional_sequence__)
  214. [endsect]
  215. [section Unbounded Iterator]
  216. [warning In this release, __unbounded_iterator__ concept has no effect. It's reserved for future release.]
  217. [endsect]
  218. [endsect]
  219. [section Functions]
  220. Fusion provides functions for manipulating iterators, analogous to the similar functions
  221. from the __mpl__ library.
  222. [section deref]
  223. [heading Description]
  224. Deferences an iterator.
  225. [heading Synopsis]
  226. template<
  227. typename I
  228. >
  229. typename __result_of_deref__<I>::type deref(I const& i);
  230. [table Parameters
  231. [[Parameter] [Requirement] [Description]]
  232. [[`i`] [Model of __forward_iterator__] [Operation's argument]]
  233. ]
  234. [heading Expression Semantics]
  235. __deref__(i);
  236. [*Return type]: `__result_of_deref__<I>::type`
  237. [*Semantics]: Dereferences the iterator `i`.
  238. [heading Header]
  239. #include <boost/fusion/iterator/deref.hpp>
  240. #include <boost/fusion/include/deref.hpp>
  241. [heading Example]
  242. typedef __vector__<int,int&> vec;
  243. int i(0);
  244. vec v(1,i);
  245. assert(__deref__(__begin__(v)) == 1);
  246. assert(__deref__(__next__(__begin__(v))) == 0);
  247. assert(&(__deref__(__next__(__begin__(v)))) == &i);
  248. [endsect]
  249. [section next]
  250. [heading Description]
  251. Moves an iterator 1 position forwards.
  252. [heading Synopsis]
  253. template<
  254. typename I
  255. >
  256. typename __result_of_next__<I>::type next(I const& i);
  257. [table Parameters
  258. [[Parameter] [Requirement] [Description]]
  259. [[`i`] [Model of __forward_iterator__] [Operation's argument]]
  260. ]
  261. [heading Expression Semantics]
  262. next(i);
  263. [*Return type]: A model of the same iterator concept as `i`.
  264. [*Semantics]: Returns an iterator to the next element after `i`.
  265. [heading Header]
  266. #include <boost/fusion/iterator/next.hpp>
  267. #include <boost/fusion/include/next.hpp>
  268. [heading Example]
  269. typedef __vector__<int,int,int> vec;
  270. vec v(1,2,3);
  271. assert(__deref__(__begin__(v)) == 1);
  272. assert(__deref__(__next__(__begin__(v))) == 2);
  273. assert(__deref__(__next__(__next__(__begin__(v)))) == 3);
  274. [endsect]
  275. [section prior]
  276. [heading Description]
  277. Moves an iterator 1 position backwards.
  278. [heading Synopsis]
  279. template<
  280. typename I
  281. >
  282. typename __result_of_prior__<I>::type prior(I const& i);
  283. [table Parameters
  284. [[Parameter] [Requirement] [Description]]
  285. [[`i`] [Model of __bidirectional_iterator__] [Operation's argument]]
  286. ]
  287. [heading Expression Semantics]
  288. __prior__(i);
  289. [*Return type]: A model of the same iterator concept as `i`.
  290. [*Semantics]: Returns an iterator to the element prior to `i`.
  291. [heading Header]
  292. #include <boost/fusion/iterator/prior.hpp>
  293. #include <boost/fusion/include/prior.hpp>
  294. [heading Example]
  295. typedef __vector__<int,int> vec;
  296. vec v(1,2);
  297. assert(__deref__(__next__(__begin__(v))) == 2);
  298. assert(__deref__(__prior__(__next__(__begin__(v)))) == 1);
  299. [endsect]
  300. [section distance]
  301. [heading Description]
  302. Returns the distance between 2 iterators.
  303. [heading Synopsis]
  304. template<
  305. typename I,
  306. typename J
  307. >
  308. typename __result_of_distance__<I, J>::type distance(I const& i, J const& j);
  309. [table Parameters
  310. [[Parameter] [Requirement] [Description]]
  311. [[`i`, `j`] [Models of __forward_iterator__ into the same sequence] [The start and end points of the distance to be measured]]
  312. ]
  313. [heading Expression Semantics]
  314. __distance__(i,j);
  315. [*Return type]: `int`
  316. [*Semantics]: Returns the distance between iterators `i` and `j`.
  317. [heading Header]
  318. #include <boost/fusion/iterator/distance.hpp>
  319. #include <boost/fusion/include/distance.hpp>
  320. [heading Example]
  321. typedef __vector__<int,int,int> vec;
  322. vec v(1,2,3);
  323. assert(__distance__(__begin__(v), __next__(__next__(__begin__(v)))) == 2);
  324. [endsect]
  325. [section advance]
  326. [heading Description]
  327. Moves an iterator by a specified distance.
  328. [heading Synopsis]
  329. template<
  330. typename M,
  331. typename I
  332. >
  333. typename __result_of_advance__<I, M>::type advance(I const& i);
  334. [table Parameters
  335. [[Parameter] [Requirement] [Description]]
  336. [[`i`] [Model of __forward_iterator__] [Iterator to move relative to]]
  337. [[`M`] [An __mpl_integral_constant__] [Number of positions to move]]
  338. ]
  339. [heading Expression Semantics]
  340. __advance__<M>(i);
  341. [*Return type]: A model of the same iterator concept as `i`.
  342. [*Semantics]: Returns an iterator to the element `M` positions from `i`. If `i` is a __bidirectional_iterator__ then `M` may be negative.
  343. [heading Header]
  344. #include <boost/fusion/iterator/advance.hpp>
  345. #include <boost/fusion/include/advance.hpp>
  346. [heading Example]
  347. typedef __vector__<int,int,int> vec;
  348. vec v(1,2,3);
  349. assert(__deref__(__advance__<mpl::int_<2> >(__begin__(v))) == 3);
  350. [endsect]
  351. [section advance_c]
  352. [heading Description]
  353. Moves an iterator by a specified distance.
  354. [heading Synopsis]
  355. template<
  356. int N,
  357. typename I
  358. >
  359. typename __result_of_advance_c__<I, N>::type advance_c(I const& i);
  360. [table Parameters
  361. [[Parameter] [Requirement] [Description]]
  362. [[`i`] [Model of __forward_iterator__] [Iterator to move relative to]]
  363. [[`N`] [Integer constant] [Number of positions to move]]
  364. ]
  365. [heading Expression Semantics]
  366. __advance_c__<N>(i);
  367. [*Return type]: A model of the same iterator concept as `i`.
  368. [*Semantics]: Returns an iterator to the element `N` positions from `i`. If `i` is a __bidirectional_iterator__ then `N` may be negative.
  369. [heading Header]
  370. #include <boost/fusion/iterator/advance.hpp>
  371. #include <boost/fusion/include/advance.hpp>
  372. [heading Example]
  373. typedef __vector__<int,int,int> vec;
  374. vec v(1,2,3);
  375. assert(__deref__(__advance_c__<2>(__begin__(v))) == 3);
  376. [endsect]
  377. [section deref_data]
  378. [heading Description]
  379. Deferences the data property associated with the element referenced by an associative iterator.
  380. [heading Synopsis]
  381. template<
  382. typename I
  383. >
  384. typename __result_of_deref_data__<I>::type deref_data(I const& i);
  385. [table Parameters
  386. [[Parameter] [Requirement] [Description]]
  387. [[`i`] [Model of __associative_iterator__] [Operation's argument]]
  388. ]
  389. [heading Expression Semantics]
  390. __deref_data__(i);
  391. [*Return type]: `__result_of_deref_data__<I>::type`
  392. [*Semantics]: Dereferences the data property associated with the element referenced by an associative iterator `i`.
  393. [heading Header]
  394. #include <boost/fusion/iterator/deref_data.hpp>
  395. #include <boost/fusion/include/deref_data.hpp>
  396. [heading Example]
  397. typedef __map__<__pair__<float, int&> > map;
  398. int i(0);
  399. map m(1.0f,i);
  400. assert(__deref_data__(__begin__(m)) == 0);
  401. assert(&(__deref_data__(__begin__(m))) == &i);
  402. [endsect]
  403. [endsect]
  404. [section Operator]
  405. Overloaded operators are provided to provide a more natural syntax for dereferencing iterators, and comparing them for equality.
  406. [section:operator_unary_star Operator *]
  407. [heading Description]
  408. Dereferences an iterator.
  409. [heading Synopsis]
  410. template<
  411. typename I
  412. >
  413. typename __result_of_deref__<I>::type operator*(I const& i);
  414. [table Parameters
  415. [[Parameter] [Requirement] [Description]]
  416. [[`i`] [Model of __forward_iterator__] [Operation's argument]]
  417. ]
  418. [heading Expression Semantics]
  419. *i
  420. [*Return type]: Equivalent to the return type of `__deref__(i)`.
  421. [*Semantics]: Equivalent to `__deref__(i)`.
  422. [heading Header]
  423. #include <boost/fusion/iterator/deref.hpp>
  424. #include <boost/fusion/include/deref.hpp>
  425. [heading Example]
  426. typedef __vector__<int,int&> vec;
  427. int i(0);
  428. vec v(1,i);
  429. assert(*__begin__(v) == 1);
  430. assert(*__next__(__begin__(v)) == 0);
  431. assert(&(*__next__(__begin__(v))) == &i);
  432. [endsect]
  433. [section:operator_equality Operator ==]
  434. [heading Description]
  435. Compares 2 iterators for equality.
  436. [heading Synopsis]
  437. template<
  438. typename I,
  439. typename J
  440. >
  441. __unspecified__ operator==(I const& i, J const& i);
  442. [table Parameters
  443. [[Parameter] [Requirement] [Description]]
  444. [[`i`, `j`] [Any fusion iterators] [Operation's arguments]]
  445. ]
  446. [heading Expression Semantics]
  447. i == j
  448. [*Return type]: Convertible to `bool`.
  449. [*Semantics]: Equivalent to `__result_of_equal_to__<I,J>::value` where `I` and `J` are the types of `i` and `j` respectively.
  450. [heading Header]
  451. #include <boost/fusion/iterator/equal_to.hpp>
  452. #include <boost/fusion/include/equal_to.hpp>
  453. [endsect]
  454. [section:operator_inequality Operator !=]
  455. [heading Description]
  456. Compares 2 iterators for inequality.
  457. [heading Synopsis]
  458. template<
  459. typename I,
  460. typename J
  461. >
  462. __unspecified__ operator==(I const& i, J const& i);
  463. [table Parameters
  464. [[Parameter] [Requirement] [Description]]
  465. [[`i`, `j`] [Any fusion iterators] [Operation's arguments]]
  466. ]
  467. [heading Expression Semantics]
  468. [*Return type]: Convertible to `bool`.
  469. [*Semantics]: Equivalent to `!__result_of_equal_to__<I,J>::value` where `I` and `J` are the types of `i` and `j` respectively.
  470. [heading Header]
  471. #include <boost/fusion/iterator/equal_to.hpp>
  472. #include <boost/fusion/include/equal_to.hpp>
  473. [endsect]
  474. [endsect]
  475. [section Metafunctions]
  476. [section value_of]
  477. [heading Description]
  478. Returns the type stored at the position of an iterator.
  479. [heading Synopsis]
  480. template<
  481. typename I
  482. >
  483. struct value_of
  484. {
  485. typedef __unspecified__ type;
  486. };
  487. [table Parameters
  488. [[Parameter] [Requirement] [Description]]
  489. [[`I`] [Model of __forward_iterator__] [Operation's argument]]
  490. ]
  491. [heading Expression Semantics]
  492. __result_of_value_of__<I>::type
  493. [*Return type]: Any type
  494. [*Semantics]: Returns the type stored in a sequence at iterator position `I`.
  495. [heading Header]
  496. #include <boost/fusion/iterator/value_of.hpp>
  497. #include <boost/fusion/include/value_of.hpp>
  498. [heading Example]
  499. typedef __vector__<int,int&,const int&> vec;
  500. typedef __result_of_begin__<vec>::type first;
  501. typedef __result_of_next__<first>::type second;
  502. typedef __result_of_next__<second>::type third;
  503. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_of__<first>::type, int>));
  504. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_of__<second>::type, int&>));
  505. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_of__<third>::type, const int&>));
  506. [endsect]
  507. [section deref]
  508. [heading Description]
  509. Returns the type that will be returned by dereferencing an iterator.
  510. [heading Synopsis]
  511. template<
  512. typename I
  513. >
  514. struct deref
  515. {
  516. typedef __unspecified__ type;
  517. };
  518. [table Parameters
  519. [[Parameter] [Requirement] [Description]]
  520. [[`I`] [Model of __forward_iterator__] [Operation's argument]]
  521. ]
  522. [heading Expression Semantics]
  523. __result_of_deref__<I>::type
  524. [*Return type]: Any type
  525. [*Semantics]: Returns the result of dereferencing an iterator of type `I`.
  526. [heading Header]
  527. #include <boost/fusion/iterator/deref.hpp>
  528. #include <boost/fusion/include/deref.hpp>
  529. [heading Example]
  530. typedef __vector__<int,int&> vec;
  531. typedef const vec const_vec;
  532. typedef __result_of_begin__<vec>::type first;
  533. typedef __result_of_next__<first>::type second;
  534. typedef __result_of_begin__<const_vec>::type const_first;
  535. typedef __result_of_next__<const_first>::type const_second;
  536. BOOST_MPL_ASSERT((boost::is_same<__result_of_deref__<first>::type, int&>));
  537. BOOST_MPL_ASSERT((boost::is_same<__result_of_deref__<second>::type, int&>));
  538. [endsect]
  539. [section next]
  540. [heading Description]
  541. Returns the type of the next iterator in a sequence.
  542. [heading Synopsis]
  543. template<
  544. typename I
  545. >
  546. struct next
  547. {
  548. typedef __unspecified__ type;
  549. };
  550. [table Parameters
  551. [[Parameter] [Requirement] [Description]]
  552. [[`I`] [Model of __forward_iterator__] [Operation's argument]]
  553. ]
  554. [heading Expression Semantics]
  555. __result_of_next__<I>::type
  556. [*Return type]: A model of the same iterator concept as `I`.
  557. [*Semantics]: Returns an iterator to the next element in the sequence after `I`.
  558. [heading Header]
  559. #include <boost/fusion/iterator/next.hpp>
  560. #include <boost/fusion/include/next.hpp>
  561. [heading Example]
  562. typedef __vector__<int,double> vec;
  563. typedef __result_of_next__<__result_of_begin__<vec>::type>::type second;
  564. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_of__<second>::type, double>));
  565. [endsect]
  566. [section prior]
  567. [heading Description]
  568. Returns the type of the previous iterator in a sequence.
  569. [heading Synopsis]
  570. template<
  571. typename I
  572. >
  573. struct prior
  574. {
  575. typedef __unspecified__ type;
  576. };
  577. [table Parameters
  578. [[Parameter] [Requirement] [Description]]
  579. [[`I`] [Model of __bidirectional_iterator__] [Operation's argument]]
  580. ]
  581. [heading Expression Semantics]
  582. __result_of_prior__<I>::type
  583. [*Return type]: A model of the same iterator concept as `I`.
  584. [*Semantics]: Returns an iterator to the previous element in the sequence before `I`.
  585. [heading Header]
  586. #include <boost/fusion/iterator/prior.hpp>
  587. #include <boost/fusion/include/prior.hpp>
  588. [heading Example]
  589. typedef __vector__<int,double> vec;
  590. typedef __result_of_next__<__result_of_begin__<vec>::type>::type second;
  591. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_of__<second>::type, double>));
  592. typedef __result_of_prior__<second>::type first;
  593. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_of__<first>::type, int>));
  594. [endsect]
  595. [section equal_to]
  596. [heading Description]
  597. Returns a true-valued __mpl_integral_constant__ if `I` and `J` are equal.
  598. [heading Synopsis]
  599. template<
  600. typename I,
  601. typename J
  602. >
  603. struct equal_to
  604. {
  605. typedef __unspecified__ type;
  606. };
  607. [table Parameters
  608. [[Parameter] [Requirement] [Description]]
  609. [[`I`, `J`] [Any fusion iterators] [Operation's arguments]]
  610. ]
  611. [heading Expression Semantics]
  612. __result_of_equal_to__<I, J>::type
  613. [*Return type]: A model of __mpl_integral_constant__.
  614. [*Semantics]: Returns `boost::mpl::true_` if `I` and `J` are iterators to the same position. Returns `boost::mpl::false_` otherwise.
  615. [heading Header]
  616. #include <boost/fusion/iterator/equal_to.hpp>
  617. #include <boost/fusion/include/equal_to.hpp>
  618. [heading Example]
  619. typedef __vector__<int,double> vec;
  620. typedef __result_of_begin__<vec>::type first;
  621. typedef __result_of_end__<vec>::type last;
  622. BOOST_MPL_ASSERT((__result_of_equal_to__<first, first>));
  623. BOOST_MPL_ASSERT_NOT((__result_of_equal_to__<first,last>));
  624. [endsect]
  625. [section distance]
  626. [heading Description]
  627. Returns the distance between two iterators.
  628. [heading Synopsis]
  629. template<
  630. typename I,
  631. typename J
  632. >
  633. struct distance
  634. {
  635. typedef __unspecified__ type;
  636. };
  637. [table Parameters
  638. [[Parameter] [Requirement] [Description]]
  639. [[`I`, `J`] [Models of __forward_iterator__ into the same sequence] [The start and end points of the distance to be measured]]
  640. ]
  641. [heading Expression Semantics]
  642. __result_of_distance__<I, J>::type
  643. [*Return type]: A model of __mpl_integral_constant__.
  644. [*Semantics]: Returns the distance between iterators of types `I` and `J`.
  645. [heading Header]
  646. #include <boost/fusion/iterator/distance.hpp>
  647. #include <boost/fusion/include/distance.hpp>
  648. [heading Example]
  649. typedef __vector__<int,double,char> vec;
  650. typedef __result_of_begin__<vec>::type first;
  651. typedef __result_of_next__<first>::type second;
  652. typedef __result_of_next__<second>::type third;
  653. typedef __result_of_distance__<first,third>::type dist;
  654. BOOST_MPL_ASSERT_RELATION(dist::value, ==, 2);
  655. [endsect]
  656. [section advance]
  657. [heading Description]
  658. Moves an iterator a specified distance.
  659. [heading Synopsis]
  660. template<
  661. typename I,
  662. typename M
  663. >
  664. struct advance
  665. {
  666. typedef __unspecified__ type;
  667. };
  668. [table Parameters
  669. [[Parameter] [Requirement] [Description]]
  670. [[`I`] [Model of __forward_iterator__] [Iterator to move relative to]]
  671. [[`M`] [Model of __mpl_integral_constant__] [Number of positions to move]]
  672. ]
  673. [heading Expression Semantics]
  674. __result_of_advance__<I,M>::type
  675. [*Return type]: A model of the same iterator concept as `I`.
  676. [*Semantics]: Returns an iterator a distance `M` from `I`. If `I` is a __bidirectional_iterator__ then `M` may be negative.
  677. [heading Header]
  678. #include <boost/fusion/iterator/advance.hpp>
  679. #include <boost/fusion/include/advance.hpp>
  680. [heading Example]
  681. typedef __vector__<int,double,char> vec;
  682. typedef __result_of_begin__<vec>::type first;
  683. typedef __result_of_next__<first>::type second;
  684. typedef __result_of_next__<second>::type third;
  685. BOOST_MPL_ASSERT((__result_of_equal_to__<__result_of_advance__<first, boost::mpl::int_<2> >::type, third>));
  686. [endsect]
  687. [section advance_c]
  688. [heading Description]
  689. Moves an iterator by a specified distance.
  690. [heading Synopsis]
  691. template<
  692. typename I,
  693. int N
  694. >
  695. struct advance_c
  696. {
  697. typedef __unspecified__ type;
  698. };
  699. [table Parameters
  700. [[Parameter] [Requirement] [Description]]
  701. [[`I`] [Model of __forward_iterator__] [Iterator to move relative to]]
  702. [[`N`] [Integer constant] [Number of positions to move]]
  703. ]
  704. [heading Expression Semantics]
  705. __result_of_advance_c__<I, N>::type
  706. [*Return type]: A model of the same iterator concept as `I`.
  707. [*Semantics]: Returns an iterator a distance `N` from `I`. If `I` is a __bidirectional_iterator__ then `N` may be negative. Equivalent to `__result_of_advance__<I, boost::mpl::int_<N> >::type`.
  708. [heading Header]
  709. #include <boost/fusion/iterator/advance.hpp>
  710. #include <boost/fusion/include/advance.hpp>
  711. [heading Example]
  712. typedef __vector__<int,double,char> vec;
  713. typedef __result_of_begin__<vec>::type first;
  714. typedef __result_of_next__<first>::type second;
  715. typedef __result_of_next__<second>::type third;
  716. BOOST_MPL_ASSERT((__result_of_equal_to__<__result_of_advance_c__<first, 2>::type, third>));
  717. [endsect]
  718. [section key_of]
  719. [heading Description]
  720. Returns the key type associated with the element referenced by an associative iterator.
  721. [heading Synopsis]
  722. template<
  723. typename I
  724. >
  725. struct key_of
  726. {
  727. typedef __unspecified__ type;
  728. };
  729. [table Parameters
  730. [[Parameter] [Requirement] [Description]]
  731. [[`I`] [Model of __associative_iterator__] [Operation's argument]]
  732. ]
  733. [heading Expression Semantics]
  734. __result_of_key_of__<I>::type
  735. [*Return type]: Any type
  736. [*Semantics]: Returns the key type associated with the element referenced by an associative iterator `I`.
  737. [heading Header]
  738. #include <boost/fusion/iterator/key_of.hpp>
  739. #include <boost/fusion/include/key_of.hpp>
  740. [heading Example]
  741. typedef __map__<__pair__<float,int> > vec;
  742. typedef __result_of_begin__<vec>::type first;
  743. BOOST_MPL_ASSERT((boost::is_same<__result_of_key_of__<first>::type, float>));
  744. [endsect]
  745. [section value_of_data]
  746. [heading Description]
  747. Returns the type of the data property associated with the element referenced by an associative iterator references.
  748. [heading Synopsis]
  749. template<
  750. typename I
  751. >
  752. struct value_of_data
  753. {
  754. typedef __unspecified__ type;
  755. };
  756. [table Parameters
  757. [[Parameter] [Requirement] [Description]]
  758. [[`I`] [Model of __associative_iterator__] [Operation's argument]]
  759. ]
  760. [heading Expression Semantics]
  761. __result_of_value_of_data__<I>::type
  762. [*Return type]: Any type
  763. [*Semantics]: Returns the type of the data property associated with the element referenced by an associative iterator `I`.
  764. [heading Header]
  765. #include <boost/fusion/iterator/value_of_data.hpp>
  766. #include <boost/fusion/include/value_of_data.hpp>
  767. [heading Example]
  768. typedef __map__<__pair__<float,int> > vec;
  769. typedef __result_of_begin__<vec>::type first;
  770. BOOST_MPL_ASSERT((boost::is_same<__result_of_value_of_data__<first>::type, int>));
  771. [endsect]
  772. [section deref_data]
  773. [heading Description]
  774. Returns the type that will be returned by dereferencing the data property referenced by an associative iterator.
  775. [heading Synopsis]
  776. template<
  777. typename I
  778. >
  779. struct deref_data
  780. {
  781. typedef __unspecified__ type;
  782. };
  783. [table Parameters
  784. [[Parameter] [Requirement] [Description]]
  785. [[`I`] [Model of __associative_iterator__] [Operation's argument]]
  786. ]
  787. [heading Expression Semantics]
  788. __result_of_deref_data__<I>::type
  789. [*Return type]: Any type
  790. [*Semantics]: Returns the result of dereferencing the data property referenced by an associative iterator of type `I`.
  791. [heading Header]
  792. #include <boost/fusion/iterator/deref_data.hpp>
  793. #include <boost/fusion/include/deref_data.hpp>
  794. [heading Example]
  795. typedef map<pair<float, int> > map_type;
  796. typedef boost::fusion::result_of::begin<map_type>::type i_type;
  797. typedef boost::fusion::result_of::deref_data<i_type>::type r_type;
  798. BOOST_STATIC_ASSERT((boost::is_same<r_type, int&>::value));
  799. [endsect]
  800. [endsect]
  801. [endsect]