00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ADOBE_ALGORITHM_COPY_HPP
00010 #define ADOBE_ALGORITHM_COPY_HPP
00011
00012 #include <adobe/config.hpp>
00013
00014 #include <boost/range/begin.hpp>
00015 #include <boost/range/end.hpp>
00016 #include <boost/range/size.hpp>
00017
00018 #include <algorithm>
00019 #include <iterator>
00020
00021
00022
00023 namespace adobe {
00024
00025
00035
00036
00042 template <class InputRange, class OutputIterator>
00043 inline OutputIterator copy(const InputRange& range, OutputIterator result)
00044 {
00045 return std::copy(boost::begin(range), boost::end(range), result);
00046 }
00047
00053 template <class BidirectionalRange1, class BidirectionalIterator2>
00054 inline BidirectionalIterator2 copy_backward(BidirectionalRange1& range1, BidirectionalIterator2 result)
00055 {
00056 return std::copy_backward(boost::begin(range1), boost::end(range1), result);
00057 }
00058
00064 template <class BidirectionalRange1, class BidirectionalIterator2>
00065 inline BidirectionalIterator2 copy_backward(const BidirectionalRange1& range1, BidirectionalIterator2 result)
00066 {
00067 return std::copy_backward(boost::begin(range1), boost::end(range1), result);
00068 }
00069
00070
00071 #ifndef ADOBE_NO_DOCUMENTATION
00072 namespace implementation {
00073
00074
00079 template <class InputIter, class Size, class OutputIter>
00080 std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count,
00081 OutputIter result,
00082 std::input_iterator_tag)
00083 {
00084 for ( ; count > 0; --count) {
00085 *result = *first;
00086 ++first;
00087 ++result;
00088 }
00089 return std::pair<InputIter, OutputIter>(first, result);
00090 }
00091
00097 template <class RAIter, class Size, class OutputIter>
00098 inline std::pair<RAIter, OutputIter>
00099 copy_n(RAIter first, Size count, OutputIter result, std::random_access_iterator_tag)
00100 {
00101 RAIter last = first + count;
00102 return std::pair<RAIter, OutputIter>(last, std::copy(first, last, result));
00103 }
00104
00105
00106
00107 }
00108 #endif
00109
00110
00116 template <class InputIter, class Size, class OutputIter>
00117 inline std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count, OutputIter result)
00118 {
00119 return implementation::copy_n(first, count, result,
00120 typename std::iterator_traits<InputIter>::iterator_category());
00121 }
00122
00123
00124
00125 #ifndef ADOBE_NO_DOCUMENTATION
00126 namespace implementation {
00127
00128
00135 template <typename I,
00136 typename F>
00137 inline std::pair<I, F> copy_bounded(I first, I last,
00138 F result_first, F result_last,
00139 std::random_access_iterator_tag, std::random_access_iterator_tag)
00140 {
00141 return adobe::copy_n(first, std::min(last - first, result_last - result_first), result_first);
00142 }
00143
00149 template <typename I,
00150 typename F>
00151 inline std::pair<I, F> copy_bounded(I first, I last,
00152 F result_first, F result_last,
00153 std::input_iterator_tag, std::forward_iterator_tag)
00154 {
00155 while (first != last && result_first != result_last)
00156 {
00157 *result_first = *first;
00158 ++first; ++result_first;
00159 }
00160
00161 return std::make_pair(first, result_first);
00162 }
00163
00164
00165
00166 }
00167 #endif
00168
00169
00175 template <typename I,
00176 typename F>
00177 inline std::pair<I, F> copy_bounded(I first, I last, F result_first, F result_last)
00178 {
00179 return implementation::copy_bounded(first, last, result_first, result_last,
00180 typename std::iterator_traits<I>::iterator_category(),
00181 typename std::iterator_traits<F>::iterator_category());
00182 }
00183
00184
00185
00191 template <typename I,
00192 typename O,
00193 typename T>
00194 inline std::pair<I, O> copy_sentinal(I f, O o, const T& x)
00195 {
00196 while (*f != x) {
00197 *o = *f;
00198 ++f, ++o;
00199 }
00200 return std::make_pair(f, o);
00201 }
00202
00203
00204
00210 template <typename I,
00211 typename O>
00212 inline std::pair<I, O> copy_sentinal(I f, O o)
00213 {
00214 return copy_sentinal(f, o, typename std::iterator_traits<I>::value_type());
00215 }
00216
00217
00218
00219 }
00220
00221
00222
00223 #endif
00224
00225