stlab.adobe.com Adobe Systems Incorporated
copy.hpp
Go to the documentation of this file.
1 /*
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)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_ALGORITHM_COPY_HPP
10 #define ADOBE_ALGORITHM_COPY_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <boost/range/begin.hpp>
15 #include <boost/range/end.hpp>
16 #include <boost/range/size.hpp>
17 
18 #include <algorithm>
19 #include <iterator>
20 
21 /*************************************************************************************************/
22 
23 namespace adobe {
24 
25 /*************************************************************************************************/
35 /*************************************************************************************************/
36 
42 template <class InputRange, class OutputIterator>
43 inline OutputIterator copy(const InputRange& range, OutputIterator result)
44 {
45  return std::copy(boost::begin(range), boost::end(range), result);
46 }
47 
53 template <class BidirectionalRange1, class BidirectionalIterator2>
54 inline BidirectionalIterator2 copy_backward(BidirectionalRange1& range1, BidirectionalIterator2 result)
55 {
56  return std::copy_backward(boost::begin(range1), boost::end(range1), result);
57 }
58 
64 template <class BidirectionalRange1, class BidirectionalIterator2>
65 inline BidirectionalIterator2 copy_backward(const BidirectionalRange1& range1, BidirectionalIterator2 result)
66 {
67  return std::copy_backward(boost::begin(range1), boost::end(range1), result);
68 }
69 
70 /*************************************************************************************************/
71 #ifndef ADOBE_NO_DOCUMENTATION
72 namespace implementation {
73 
74 /*************************************************************************************************/
79 template <class InputIter, class Size, class OutputIter>
80 std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count,
81  OutputIter result,
82  std::input_iterator_tag)
83 {
84  for ( ; count > 0; --count) {
85  *result = *first;
86  ++first;
87  ++result;
88  }
89  return std::pair<InputIter, OutputIter>(first, result);
90 }
91 
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)
100 {
101  RAIter last = first + count;
102  return std::pair<RAIter, OutputIter>(last, std::copy(first, last, result));
103 }
104 
105 /*************************************************************************************************/
106 
107 } // namespace implementation
108 #endif
109 /*************************************************************************************************/
110 
116 template <class InputIter, class Size, class OutputIter>
117 inline std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count, OutputIter result)
118 {
119  return implementation::copy_n(first, count, result,
120  typename std::iterator_traits<InputIter>::iterator_category());
121 }
122 
123 /*************************************************************************************************/
124 
125 #ifndef ADOBE_NO_DOCUMENTATION
126 namespace implementation {
127 
128 /*************************************************************************************************/
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)
140 {
141  return adobe::copy_n(first, std::min(last - first, result_last - result_first), result_first);
142 }
143 
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)
154 {
155  while (first != last && result_first != result_last)
156  {
157  *result_first = *first;
158  ++first; ++result_first;
159  }
160 
161  return std::make_pair(first, result_first);
162 }
163 
164 /*************************************************************************************************/
165 
166 } // namespace implementation
167 #endif
168 
169 /*************************************************************************************************/
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)
178 {
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());
182 }
183 
184 /*************************************************************************************************/
185 
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)
195 {
196  while (*f != x) {
197  *o = *f;
198  ++f, ++o;
199  }
200  return std::make_pair(f, o);
201 }
202 
203 /*************************************************************************************************/
204 
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)
213 {
214  return copy_sentinal(f, o, typename std::iterator_traits<I>::value_type());
215 }
216 
217 /*************************************************************************************************/
218 
219 } // namespace adobe
220 
221 /*************************************************************************************************/
222 
223 #endif
224 
225 /*************************************************************************************************/
std::pair< InputIter, OutputIter > copy_n(InputIter first, Size count, OutputIter result)
copy implementation
Definition: copy.hpp:117
std::pair< I, O > copy_sentinal(I f, O o, const T &x)
copy implementation
Definition: copy.hpp:194
OutputIterator copy(const InputRange &range, OutputIterator result)
copy implementation
Definition: copy.hpp:43
const T &() min(const T &a, const T &b)
minmax implementation
Definition: minmax.hpp:66
BidirectionalIterator2 copy_backward(BidirectionalRange1 &range1, BidirectionalIterator2 result)
copy implementation
Definition: copy.hpp:54
std::pair< I, F > copy_bounded(I first, I last, F result_first, F result_last)
copy implementation
Definition: copy.hpp:177
boost::range_difference< InputRange >::type count(InputRange &range, T &value)
count implementation
Definition: count.hpp:41
pair< T1, T2 > make_pair(T1 x, T2 y)
Definition: pair.hpp:109
BidirectionalIterator2 copy_backward(const BidirectionalRange1 &range1, BidirectionalIterator2 result)
copy implementation
Definition: copy.hpp:65

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google