functions_element_iteration.qbk 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. [/
  2. Copyright (c) 2008-2009 Joachim Faulhaber
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. ]
  7. [/ //= Element iteration ===================================================================]
  8. [section Element iteration]
  9. This section refers to ['*element iteration*] over ['*interval containers*].
  10. Element iterators are available as associated types on interval sets and interval maps.
  11. [table
  12. [[Variant] [Associated element iterator type for interval container `T`]]
  13. [[forward] [`T::element_iterator`] ]
  14. [[const forward][`T::element_const_iterator`] ]
  15. [[reverse] [`T::element_reverse_iterator`] ]
  16. [[const reverse][`T::element_const_reverse_iterator`] ]
  17. ]
  18. There are also associated iterators types
  19. `T::iterator`, `T::const_iterator`,
  20. `T::reverse_iterator` and `T::reverse_const_iterator`
  21. on interval containers.
  22. These are ['*segment iterators*]. Segment iterators are
  23. "first citizen iterators". [/ NOTE Identical to interface.qbk from here]
  24. Iteration over segments is fast, compared to an iteration over elements,
  25. particularly if intervals are large.
  26. But if we want to view our interval containers as containers
  27. of elements that are usable with std::algoritms, we need to
  28. iterate over elements.
  29. Iteration over elements . . .
  30. * is possible only for integral or discrete `domain_types`
  31. * can be very ['*slow*] if the intervals are very large.
  32. * and is therefore ['*depreciated*]
  33. On the other hand, sometimes iteration over interval containers
  34. on the element level might be desired, if you have some
  35. interface that works for `std::SortedAssociativeContainers` of
  36. elements and you need to quickly use it with an interval container.
  37. Accepting the poorer performance might be less bothersome at times
  38. than adjusting your whole interface for segment iteration.
  39. [caution So we advice you to choose element iteration over
  40. interval containers ['*judiciously*]. Do not use element iteration
  41. ['*by default or habitual*]. Always try to achieve results using
  42. member functions, global functions or operators
  43. (preferably inplace versions)
  44. or iteration over segments first.]
  45. [table
  46. [[['*Synopsis Complexities*]] [__ch_itv_sets__][__ch_itv_maps__]]
  47. [[`J elements_begin(T&)`] [__O1__] [__O1__] ]
  48. [[`J elements_end(T&)`] [__O1__] [__O1__] ]
  49. [[`J elements_rbegin(T&)`] [__O1__] [__O1__] ]
  50. [[`J elements_rend(T&)`] [__O1__] [__O1__] ]
  51. ]
  52. [table
  53. [[['*Element iteration*]] [Description] ]
  54. [[`` element_iterator elements_begin(T&)
  55. element_const_iterator elements_begin(const T&)``] [Returns an element iterator to the first element of the container.] ]
  56. [[`` element_iterator elements_end(T&)
  57. element_const_iterator elements_end(const T&)``] [Returns an element iterator to a position `elements_end(c)` after the last element of the container.]]
  58. [[`` element_reverse_iterator elements_rbegin(T&)
  59. element_const_reverse_iterator elements_rbegin(const T&)``] [Returns a reverse element iterator to the last element of the container.] ]
  60. [[`` element_reverse_iterator elements_rend(T&)
  61. element_const_reverse_iterator elements_rend(const T&)``] [Returns a reverse element iterator to a position `elements_rend(c)` before the first element of the container.]]
  62. ]
  63. ['*Example*]
  64. ``
  65. interval_set<int> inter_set;
  66. inter_set.add(interval<int>::right_open(0,3))
  67. .add(interval<int>::right_open(7,9));
  68. for(interval_set<int>::element_const_iterator creeper = elements_begin(inter_set);
  69. creeper != elements_end(inter_set); ++creeper)
  70. cout << *creeper << " ";
  71. cout << endl;
  72. //Program output: 0 1 2 7 8
  73. for(interval_set<int>::element_reverse_iterator repeerc = elements_rbegin(inter_set);
  74. repeerc != elements_rend(inter_set); ++repeerc)
  75. cout << *repeerc << " ";
  76. cout << endl;
  77. //Program output: 8 7 2 1 0
  78. ``
  79. ['*See also . . .*]
  80. [table
  81. []
  82. [[[link boost_icl.function_reference.iterator_related ['*Segment iteration*]] ]]
  83. ]
  84. ['*Back to section . . .*]
  85. [table
  86. []
  87. [[[link function_synopsis_table ['*Function Synopsis*]]]]
  88. [[[link boost_icl.interface ['*Interface*]] ]]
  89. ]
  90. [endsect][/ Element iteration]