00001 #ifndef _INSTIGATE_STL_INTERNAL_HEADER_IN_ALGORITHM
00002 #error This is an internal header file used to implement Instigate STL.\
00003 It should never be included directly by a program.
00004 #endif
00005
00006 #ifndef INSTIGATE_STL_ADVANCE_HPP
00007 #define INSTIGATE_STL_ADVANCE_HPP
00008
00056
00057 #include "concept.hpp"
00058 #include "_basis.hpp"
00059
00060
00061
00062
00063
00064
00065 namespace instigate {
00066 namespace stl {
00067 template <typename I>
00068 inline void advance(I&, typename stl::single_pass_iterator::
00069 interface<I>::difference_type);
00070 namespace implementation {
00071 template <typename I, typename D>
00072 inline void advance_aux(I&, D,
00073 stl::single_pass_iterator::tag);
00074 template <typename I, typename D>
00075 inline void advance_aux(I&, D,
00076 stl::bidirectional_iterator::tag);
00077 template <typename I, typename D>
00078 inline void advance_aux(I&, D,
00079 stl::random_access_iterator::tag);
00080 }
00081 }
00082 }
00083
00117 template <typename I>
00118 inline void instigate::stl::advance(I& i, typename instigate::stl::
00119 single_pass_iterator::interface<I>::difference_type n)
00120 {
00121 CHECK(stl::single_pass_iterator::requirements<I>);
00122 typedef typename instigate::stl::single_pass_iterator::
00123 interface<I>::iterator_category category;
00124 implementation::advance_aux(i, n, category());
00125 }
00126
00131 template <typename I, typename D>
00132 inline void instigate::stl::implementation::advance_aux(I& i, D n,
00133 instigate::stl::single_pass_iterator::tag)
00134 {
00135 const D a = 0;
00136 while (less_than(a, n)) {
00137 --n;
00138 increment(i);
00139 }
00140 }
00141
00146 template <typename I, typename D>
00147 inline void instigate::stl::implementation::advance_aux(I& i, D n,
00148 instigate::stl::bidirectional_iterator::tag)
00149 {
00150 CHECK(stl::bidirectional_iterator::requirements<I>);
00151 const D a = 0;
00152 if (a < n) {
00153 while(a < n) {
00154 --n;
00155 increment(i);
00156 }
00157 } else {
00158 while (0 > n) {
00159 ++n;
00160 decrement(i);
00161 }
00162 }
00163 }
00164
00169 template <typename I, typename D>
00170 inline void instigate::stl::implementation::advance_aux(I& i, D n,
00171 instigate::stl::random_access_iterator::tag)
00172 {
00173 CHECK(stl::random_access_iterator::requirements<I>);
00174 stl::random_access_iterator::interface<I>::advance(i, n);
00175 }
00176
00177
00178
00179 #endif // INSTIGATE_STL_ADVANCE_HPP