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_N_HPP
00008 #define INSTIGATE_STL_COPY_N_HPP
00009
00057
00058 #include "concept.hpp"
00059 #include "_basis.hpp"
00060 #include "_advance.hpp"
00061 #include "_copy.hpp"
00062 #include "_single_pass_iterator.hpp"
00063 #include "_random_access_iterator.hpp"
00064
00065
00066
00067
00068
00069
00070 namespace instigate {
00071 namespace stl {
00072 template <typename I, typename S, typename O, typename P>
00073 inline void copy_n(I, S, O, P&);
00074
00075 namespace implementation {
00076 template <typename I, typename S,
00077 typename O, typename P>
00078 void __copy_n(I, S, O, P&,
00079 instigate::stl::single_pass_iterator::tag);
00080
00081 template <typename I, typename S,
00082 typename O, typename P>
00083 inline void __copy_n(I, S, O, P&,
00084 instigate::stl::random_access_iterator::tag);
00085 }
00086 }
00087 }
00088
00116 template <typename I, typename S, typename O, typename P>
00117 inline void instigate::stl::copy_n(I f, S c, O r, P& ob_pair)
00118 {
00119 CHECK(instigate::stl::single_pass_iterator::requirements<I>);
00120 CHECK(instigate::stl::readable_iterator::requirements<I>);
00121 CHECK(instigate::stl::incrementable_iterator::requirements<O>);
00122 CHECK(instigate::stl::writable_iterator::requirements<O>);
00123 CHECK(instigate::stl::pair::requirements<P>);
00124 CHECK_CONVERTIBILITY(typename instigate::stl::readable_iterator::
00125 interface<I>::value_type, typename instigate::stl::
00126 writable_iterator::interface<O>::value_type);
00127 instigate::stl::implementation::__copy_n(f, c, r, ob_pair, typename
00128 instigate::stl::single_pass_iterator::interface<I>::
00129 iterator_category());
00130 }
00131
00136 template <typename I, typename S, typename O, typename P>
00137 void instigate::stl::implementation::__copy_n(I f, S c, O r,
00138 P& ob_pair, instigate::stl::single_pass_iterator::tag)
00139 {
00140 for ( ; c > 0; --c) {
00141 dereference_assign(r, const_dereference(f));
00142 increment(f);
00143 increment(r);
00144 }
00145 instigate::stl::pair::interface<P>::set_first(ob_pair, f);
00146 instigate::stl::pair::interface<P>::set_second(ob_pair, r);
00147 }
00148
00153 template <typename I, typename S, typename O, typename P>
00154 inline void instigate::stl::implementation::__copy_n(I f, S c, O r, P& ob_pair,
00155 instigate::stl::random_access_iterator::tag)
00156 {
00157 I* l = 0;
00158 char p[sizeof(I)];
00159 assign(l, copy_constructor(p, f));
00160 assert(0 != l);
00161 instigate::stl::advance(*l, c);
00162 instigate::stl::copy(f, *l, r);
00163 instigate::stl::pair::interface<P>::set_first(ob_pair, *l);
00164 instigate::stl::pair::interface<P>::set_second(ob_pair,
00165 instigate::stl::copy(f, *l, r));
00166 }
00167
00168
00169
00170 #endif // INSTIGATE_STL_COPY_N_HPP