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_COPY_BACKWARD_HPP
00008 #define INSTIGATE_STL_COPY_BACKWARD_HPP
00009
00058
00059 #include "concept.hpp"
00060 #include "_basis.hpp"
00061
00062
00063 #include <generic/base.hpp>
00064
00065
00066
00067
00068 namespace instigate {
00069 namespace stl {
00070 template <typename B1, typename B2>
00071 inline B2 copy_backward(B1, B1, B2);
00072
00073 namespace implementation {
00074 template <typename B_1, typename B_2>
00075 inline B_2 __copy_backward(B_1, B_1, B_2,
00076 instigate::stl::bidirectional_iterator::tag);
00077
00078 template <typename R, typename B>
00079 inline B __copy_backward(R, R, B,
00080 instigate::stl::random_access_iterator::tag);
00081 }
00082 }
00083 }
00084
00111 template <typename B1, typename B2>
00112 inline B2 instigate::stl::copy_backward(B1 f, B1 l, B2 r)
00113 {
00114 CHECK(instigate::stl::readable_iterator::requirements<B1>);
00115 CHECK(instigate::stl::bidirectional_iterator::requirements<B1>);
00116 CHECK(instigate::stl::lvalue_iterator::requirements<B2>);
00117 CHECK(instigate::stl::writable_iterator::requirements<B2>);
00118 CHECK(instigate::stl::bidirectional_iterator::requirements<B2>);
00119 CHECK_CONVERTIBILITY(typename instigate::stl::readable_iterator::
00120 interface<B1>::value_type, typename instigate::stl::
00121 writable_iterator::interface<B2>::value_type);
00122 return instigate::stl::implementation::__copy_backward(f, l, r,
00123 typename instigate::stl::bidirectional_iterator::
00124 interface<B1>::iterator_category());
00125 }
00126
00131 template <typename B_1, typename B_2>
00132 inline B_2 instigate::stl::implementation::__copy_backward(B_1 f, B_1 l, B_2 r,
00133 instigate::stl::bidirectional_iterator::tag)
00134 {
00135 while (!equal(f, l)) {
00136 decrement(r);
00137 decrement(l);
00138 dereference_assign(r, const_dereference(l));
00139 }
00140 return r;
00141 }
00142
00147 template <typename R, typename B>
00148 inline B instigate::stl::implementation::__copy_backward(R f, R l, B r,
00149 instigate::stl::random_access_iterator::tag)
00150 {
00151 typedef typename instigate::stl::single_pass_iterator::interface<R>::
00152 difference_type DISTANCE;
00153 for (DISTANCE n = instigate::stl::distance<R>(f, l); n > 0; --n) {
00154 decrement(r);
00155 decrement(l);
00156 dereference_assign(r, const_dereference(l));
00157 }
00158 return r;
00159 }
00160
00161
00162
00163 #endif // INSTIGATE_STL_COPY_BACKWARD_HPP