00001
00002 #ifndef _INSTIGATE_STL_INTERNAL_HEADER_IN_ALGORITHM
00003 #error This is an internal header file used to implement Instigate STL.\
00004 It should never be included directly by a program.
00005 #endif
00006
00007 #ifndef INSTIGATE_STL_REVERSE_HPP
00008 #define INSTIGATE_STL_REVERSE_HPP
00009
00058
00059 #include "concept.hpp"
00060 #include "_iter_swap.hpp"
00061
00062
00063
00064
00065
00066
00067 namespace instigate {
00068 namespace stl {
00069 template <typename B>
00070 void reverse(B b, B e);
00071 namespace implementation {
00072 template <typename B>
00073 void reverse_aux(B b, B e, instigate::stl::
00074 bidirectional_iterator::tag);
00075 template <typename R>
00076 void reverse_aux(R b, R e, instigate::stl::
00077 random_access_iterator::tag);
00078 }
00079 }
00080 }
00081
00101 template <typename B>
00102 void instigate::stl::reverse(B b, B e)
00103 {
00104 typename instigate::stl::incrementable_iterator::interface<B>::
00105 iterator_category category;
00106 implementation::reverse_aux(b, e, category);
00107 }
00108
00112 template <typename B>
00113 void instigate::stl::implementation::reverse_aux(B b, B e,
00114 instigate::stl::bidirectional_iterator::tag)
00115 {
00116 namespace BI = instigate::stl::bidirectional_iterator;
00117 namespace EQ = instigate::generic::equality_comparable;
00118 CHECK(BI::requirements<B>);
00119 while (true){
00120 if (equal(b, e)) {
00121 return;
00122 }
00123 decrement(e);
00124 if (equal(b, e)) {
00125 return;
00126 }
00127 instigate::stl::iter_swap(b, e);
00128 increment(b);
00129 }
00130 }
00131
00135 template <typename R>
00136 void instigate::stl::implementation::reverse_aux(R b, R e,
00137 instigate::stl::random_access_iterator::tag)
00138 {
00139 namespace RI = instigate::stl::random_access_iterator;
00140 CHECK(RI::requirements<R>);
00141 while (less_than(b, e))
00142 {
00143 decrement(e);
00144 instigate::stl::iter_swap(b, e);
00145 increment(b);
00146 }
00147 }
00148
00149
00150
00151 #endif // INSTIGATE_STL_REVERSE_HPP