2
Copyright 2005-2007 Adobe Systems Incorporated
3
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4
or a copy at http://stlab.adobe.com/licenses.html)
7
/*************************************************************************************************/
9
#ifndef ADOBE_ALGORITHM_COPY_HPP
10
#define ADOBE_ALGORITHM_COPY_HPP
12
#include <mlib/adobe/config.hpp>
14
#include <boost/range/begin.hpp>
15
#include <boost/range/end.hpp>
16
#include <boost/range/size.hpp>
21
/*************************************************************************************************/
25
/*************************************************************************************************/
28
\ingroup mutating_algorithm
31
- STL documentation for \ref stldoc_copy
32
- STL documentation for \ref stldoc_copy_n
33
- STL documentation for \ref stldoc_copy_backward
35
/*************************************************************************************************/
40
\brief copy implementation
42
template <class InputRange, class OutputIterator>
43
inline OutputIterator copy(const InputRange& range, OutputIterator result)
45
return std::copy(boost::begin(range), boost::end(range), result);
51
\brief copy implementation
53
template <class BidirectionalRange1, class BidirectionalIterator2>
54
inline BidirectionalIterator2 copy_backward(BidirectionalRange1& range1, BidirectionalIterator2 result)
56
return std::copy_backward(boost::begin(range1), boost::end(range1), result);
62
\brief copy implementation
64
template <class BidirectionalRange1, class BidirectionalIterator2>
65
inline BidirectionalIterator2 copy_backward(const BidirectionalRange1& range1, BidirectionalIterator2 result)
67
return std::copy_backward(boost::begin(range1), boost::end(range1), result);
70
/*************************************************************************************************/
71
#ifndef ADOBE_NO_DOCUMENTATION
72
namespace implementation {
74
/*************************************************************************************************/
77
\brief taken from SGI STL.
79
template <class InputIter, class Size, class OutputIter>
80
std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count,
82
std::input_iterator_tag)
84
for ( ; count > 0; --count) {
89
return std::pair<InputIter, OutputIter>(first, result);
95
\brief copy implementation
97
template <class RAIter, class Size, class OutputIter>
98
inline std::pair<RAIter, OutputIter>
99
copy_n(RAIter first, Size count, OutputIter result, std::random_access_iterator_tag)
101
RAIter last = first + count;
102
return std::pair<RAIter, OutputIter>(last, std::copy(first, last, result));
105
/*************************************************************************************************/
107
} // namespace implementation
109
/*************************************************************************************************/
114
\brief copy implementation
116
template <class InputIter, class Size, class OutputIter>
117
inline std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count, OutputIter result)
119
return implementation::copy_n(first, count, result,
120
typename std::iterator_traits<InputIter>::iterator_category());
123
/*************************************************************************************************/
125
#ifndef ADOBE_NO_DOCUMENTATION
126
namespace implementation {
128
/*************************************************************************************************/
132
REVIST (sparent) : There is an assumption here that the difference types of the two ranges are
133
the same. We need a way to promote the smaller integral type to the larger.
135
template <typename I, // I models RandomAccessIterator
136
typename F> // F models RandomAccessIterator
137
inline std::pair<I, F> copy_bounded(I first, I last,
138
F result_first, F result_last,
139
std::random_access_iterator_tag, std::random_access_iterator_tag)
141
return adobe::copy_n(first, std::min(last - first, result_last - result_first), result_first);
147
\brief copy implementation
149
template <typename I, // I models InputIterator
150
typename F> // F models ForwardIterator
151
inline std::pair<I, F> copy_bounded(I first, I last,
152
F result_first, F result_last,
153
std::input_iterator_tag, std::forward_iterator_tag)
155
while (first != last && result_first != result_last)
157
*result_first = *first;
158
++first; ++result_first;
161
return std::make_pair(first, result_first);
164
/*************************************************************************************************/
166
} // namespace implementation
169
/*************************************************************************************************/
173
\brief copy implementation
175
template <typename I, // I models InputIterator
176
typename F> // F models ForwardIterator
177
inline std::pair<I, F> copy_bounded(I first, I last, F result_first, F result_last)
179
return implementation::copy_bounded(first, last, result_first, result_last,
180
typename std::iterator_traits<I>::iterator_category(),
181
typename std::iterator_traits<F>::iterator_category());
184
/*************************************************************************************************/
189
\brief copy implementation
191
template <typename I, // I models InputIterator
192
typename O, // O models OutputIterator
193
typename T> // T == value_type(I)
194
inline std::pair<I, O> copy_sentinal(I f, O o, const T& x)
200
return std::make_pair(f, o);
203
/*************************************************************************************************/
208
\brief copy implementation
210
template <typename I, // I models InputIterator
211
typename O> // O models OutputIterator
212
inline std::pair<I, O> copy_sentinal(I f, O o)
214
return copy_sentinal(f, o, typename std::iterator_traits<I>::value_type());
217
/*************************************************************************************************/
221
/*************************************************************************************************/
225
/*************************************************************************************************/