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_HPP
00008 #define INSTIGATE_STL_COPY_HPP
00009
00057
00058 #include "concept.hpp"
00059 #include "_basis.hpp"
00060 #include "_distance.hpp"
00061 #include "_advance.hpp"
00062
00063
00064 #include <generic/base.hpp>
00065
00066
00067
00068
00069 namespace instigate {
00070 namespace stl {
00071 template <typename I, typename O>
00072 inline O copy(I, I, O);
00073
00080 namespace implementation {
00081 template <typename I, typename O>
00082 inline O __copy(I, I, O,
00083 instigate::stl::single_pass_iterator::tag);
00084
00085 template <typename I, typename O>
00086 inline O __copy(I, I, O,
00087 instigate::stl::random_access_iterator::tag);
00088
00089 template <typename T>
00090 inline T* copy_trivial(const T*, const T*, T*);
00091
00092 template <typename I, typename O>
00093 inline O copy_aux(I, I, O, false_type);
00094
00095 template <typename I, typename O>
00096 inline O copy_aux(I, I, O, true_type);
00097
00098 template <typename T>
00099 inline T* copy_aux(const T*, const T*, T*, true_type);
00100 }
00101 }
00102 }
00103
00127 template <typename I, typename O>
00128 inline O instigate::stl::copy(I f, I l, O r)
00129 {
00130 typedef typename instigate::stl::readable_iterator::
00131 interface<I>::value_type value_type1;
00132 typedef typename instigate::stl::writable_iterator::
00133 interface<O>::value_type value_type2;
00134 CHECK(instigate::stl::readable_iterator::requirements<I>);
00135 CHECK(instigate::stl::single_pass_iterator::requirements<I>);
00136 CHECK(instigate::stl::writable_iterator::requirements<O>);
00137 CHECK(instigate::stl::incrementable_iterator::requirements<O>);
00138 CHECK_CONVERTIBILITY(value_type1, value_type2);
00139 typedef typename unary_type_traits<value_type1>::
00140 has_trivial_assignment_operator trivial;
00141 return instigate::stl::implementation::copy_aux(f, l, r, trivial());
00142 }
00143
00144
00145
00146
00147
00148
00149
00154 template <typename I, typename O>
00155 inline O instigate::stl::implementation::__copy(I f, I l, O r,
00156 instigate::stl::single_pass_iterator::tag)
00157 {
00158 for ( ; !equal(f, l); increment(r), increment(f)) {
00159 dereference_assign(r, const_dereference(f));
00160 }
00161 return r;
00162 }
00163
00168 template <typename I, typename O>
00169 inline O instigate::stl::implementation::__copy(I f, I l, O r,
00170 instigate::stl::random_access_iterator::tag)
00171 {
00172 typedef typename instigate::stl::random_access_iterator::
00173 interface<I>::difference_type DISTANCE;
00174 for (DISTANCE n = instigate::stl::distance<I>(f,l); n > 0; --n) {
00175 dereference_assign(r, const_dereference(f));
00176 increment(r),
00177 increment(f);
00178 }
00179 return r;
00180 }
00181
00183 template <typename T>
00184 inline T* instigate::stl::implementation::copy_trivial(
00185 const T* f, const T* l, T* r)
00186 {
00187 memmove(r, f, sizeof(T) * instigate::stl::distance(f, l));
00188 instigate::stl::advance(r, instigate::stl::distance(f, l));
00189 return r;
00190 }
00191
00196 template <typename I, typename O>
00197 inline O instigate::stl::implementation::copy_aux(I f, I l, O r, false_type)
00198 {
00199 return instigate::stl::implementation::__copy(f, l, r,
00200 typename instigate::stl::single_pass_iterator::interface<I>::
00201 iterator_category());
00202 }
00203
00208 template <typename I, typename O>
00209 inline O instigate::stl::implementation::copy_aux(I f, I l, O r, true_type)
00210 {
00211 return instigate::stl::implementation::__copy(f, l, r,
00212 typename instigate::stl::single_pass_iterator::interface<I>::
00213 iterator_category());
00214 }
00215
00220 template <typename T>
00221 inline T* instigate::stl::implementation::copy_aux(const T* f, const T* l,
00222 T* r, true_type)
00223 {
00224 return instigate::stl::implementation::copy_trivial(f, l, r);
00225 }
00226
00227
00228
00229 #endif // INSTIGATE_STL_COPY_HPP