Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
copy.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_ALGORITHM_COPY_HPP
9#define ADOBE_ALGORITHM_COPY_HPP
10
11#include <adobe/config.hpp>
12
13#include <boost/range/begin.hpp>
14#include <boost/range/end.hpp>
15#include <boost/range/size.hpp>
16
17#include <algorithm>
18#include <iterator>
19
20/**************************************************************************************************/
21
22namespace adobe {
23
24/**************************************************************************************************/
34/**************************************************************************************************/
35
41template <class InputRange, class OutputIterator>
42inline OutputIterator copy(const InputRange& range, OutputIterator result) {
43 return std::copy(boost::begin(range), boost::end(range), result);
44}
45
51template <class BidirectionalRange1, class BidirectionalIterator2>
52inline BidirectionalIterator2 copy_backward(BidirectionalRange1& range1,
53 BidirectionalIterator2 result) {
54 return std::copy_backward(boost::begin(range1), boost::end(range1), result);
55}
56
62template <class BidirectionalRange1, class BidirectionalIterator2>
63inline BidirectionalIterator2 copy_backward(const BidirectionalRange1& range1,
64 BidirectionalIterator2 result) {
65 return std::copy_backward(boost::begin(range1), boost::end(range1), result);
66}
67
68/**************************************************************************************************/
69#ifndef ADOBE_NO_DOCUMENTATION
70namespace implementation {
71
72/**************************************************************************************************/
77template <class InputIter, class Size, class OutputIter>
78std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count, OutputIter result,
79 std::input_iterator_tag) {
80 for (; count > 0; --count) {
81 *result = *first;
82 ++first;
83 ++result;
84 }
85 return std::pair<InputIter, OutputIter>(first, result);
86}
87
93template <class RAIter, class Size, class OutputIter>
94inline std::pair<RAIter, OutputIter> copy_n(RAIter first, Size count, OutputIter result,
95 std::random_access_iterator_tag) {
96 RAIter last = first + count;
97 return std::pair<RAIter, OutputIter>(last, std::copy(first, last, result));
98}
99
100/**************************************************************************************************/
101
102} // namespace implementation
103#endif
104/**************************************************************************************************/
105
111template <class InputIter, class Size, class OutputIter>
112inline std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count, OutputIter result) {
113 return implementation::copy_n(first, count, result,
114 typename std::iterator_traits<InputIter>::iterator_category());
115}
116
117/**************************************************************************************************/
118
119#ifndef ADOBE_NO_DOCUMENTATION
120namespace implementation {
121
122/**************************************************************************************************/
130template <typename I, // I models RandomAccessIterator
131 typename F>
132// F models RandomAccessIterator
133inline std::pair<I, F> copy_bounded(I first, I last, F result_first, F result_last,
134 std::random_access_iterator_tag,
135 std::random_access_iterator_tag) {
136 return adobe::copy_n(first, std::min(last - first, result_last - result_first), result_first);
137}
138
144template <typename I, // I models InputIterator
145 typename F>
146// F models ForwardIterator
147inline std::pair<I, F> copy_bounded(I first, I last, F result_first, F result_last,
148 std::input_iterator_tag, std::forward_iterator_tag) {
149 while (first != last && result_first != result_last) {
150 *result_first = *first;
151 ++first;
152 ++result_first;
153 }
154
155 return std::make_pair(first, result_first);
156}
157
158/**************************************************************************************************/
159
160} // namespace implementation
161#endif
162
163/**************************************************************************************************/
169template <typename I, // I models InputIterator
170 typename F>
171// F models ForwardIterator
172inline std::pair<I, F> copy_bounded(I first, I last, F result_first, F result_last) {
173 return implementation::copy_bounded(first, last, result_first, result_last,
174 typename std::iterator_traits<I>::iterator_category(),
175 typename std::iterator_traits<F>::iterator_category());
176}
177
178/**************************************************************************************************/
179
185template <typename I, // I models InputIterator
186 typename O, // O models OutputIterator
187 typename T>
188// T == value_type(I)
189inline std::pair<I, O> copy_sentinal(I f, O o, const T& x) {
190 while (*f != x) {
191 *o = *f;
192 ++f, ++o;
193 }
194 return std::make_pair(f, o);
195}
196
197/**************************************************************************************************/
198
204template <typename I, // I models InputIterator
205 typename O>
206// O models OutputIterator
207inline std::pair<I, O> copy_sentinal(I f, O o) {
208 return copy_sentinal(f, o, typename std::iterator_traits<I>::value_type());
209}
210
211/**************************************************************************************************/
212
213} // namespace adobe
214
215/**************************************************************************************************/
216
217#endif
218
219/**************************************************************************************************/
std::pair< I, F > copy_bounded(I first, I last, F result_first, F result_last)
copy implementation
Definition copy.hpp:172
OutputIterator copy(const InputRange &range, OutputIterator result)
copy implementation
Definition copy.hpp:42
BidirectionalIterator2 copy_backward(BidirectionalRange1 &range1, BidirectionalIterator2 result)
copy implementation
Definition copy.hpp:52
std::pair< I, O > copy_sentinal(I f, O o, const T &x)
copy implementation
Definition copy.hpp:189
std::pair< InputIter, OutputIter > copy_n(InputIter first, Size count, OutputIter result)
copy implementation
Definition copy.hpp:112
boost::range_difference< InputRange >::type count(InputRange &range, T &value)
count implementation
Definition count.hpp:40