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_DISTANCE_HPP
00008 #define INSTIGATE_STL_DISTANCE_HPP
00009
00060
00061 #include "concept.hpp"
00062 #include "_basis.hpp"
00063
00064
00065
00066
00067
00068
00069 namespace instigate {
00070 namespace stl {
00072 template <typename I>
00073 inline typename stl::single_pass_iterator::interface<I>::
00074 difference_type distance(I, I);
00075 namespace implementation {
00076 template <typename I>
00077 inline typename stl::single_pass_iterator::
00078 interface<I>::difference_type
00079 distance_aux(I, I, stl::single_pass_iterator::tag);
00080
00081 template <typename I>
00082 inline typename stl::random_access_iterator::
00083 interface<I>::difference_type
00084 distance_aux(I, I, stl::random_access_iterator::tag);
00085 }
00086 }
00087 }
00088
00109 template <typename I>
00110 inline typename instigate::stl::single_pass_iterator::interface<I>::
00111 difference_type instigate::stl::distance(I b, I e)
00112 {
00113 CHECK(stl::single_pass_iterator::requirements<I>);
00114 CHECK(stl::readable_iterator::requirements<I>);
00115 typedef typename stl::single_pass_iterator::interface<I>::
00116 iterator_category category;
00117 return implementation::distance_aux(b, e, category());
00118 }
00119
00124 template <typename I>
00125 inline typename instigate::stl::single_pass_iterator::interface<I>::
00126 difference_type instigate::stl::implementation::distance_aux(
00127 I b,
00128 I e,
00129 instigate::stl::single_pass_iterator::tag)
00130 {
00131 typedef typename instigate::stl::single_pass_iterator::
00132 interface<I>::difference_type Distance;
00133 Distance n = 0;
00134 while (!equal(b, e)) {
00135 increment(b);
00136 ++n;
00137 }
00138 return n;
00139 }
00140
00145 template <typename I>
00146 inline typename instigate::stl::random_access_iterator::
00147 interface<I>::difference_type
00148 instigate::stl::implementation::distance_aux(
00149 I b,
00150 I e,
00151 instigate::stl::random_access_iterator::tag)
00152 {
00153 CHECK(stl::random_access_iterator::requirements<I>);
00154 return stl::random_access_iterator::interface<I>::distance(b, e);
00155 }
00156
00157
00158
00159 #endif // INSTIGATE_STL_DISTANCE_HPP