Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
find.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_FIND_HPP
9#define ADOBE_ALGORITHM_FIND_HPP
10
11#include <adobe/config.hpp>
12
13#include <algorithm>
14#include <functional>
15#include <utility>
16
17#include <boost/next_prior.hpp>
18#include <boost/range/begin.hpp>
19#include <boost/range/end.hpp>
20
21/**************************************************************************************************/
22
23namespace adobe {
24
25/**************************************************************************************************/
37
38/**************************************************************************************************/
39
54
55/**************************************************************************************************/
56
57/**************************************************************************************************/
72/**************************************************************************************************/
78template <class InputIterator, class Predicate>
79inline InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pred) {
80 return std::find_if_not(first, last, std::bind(pred, std::placeholders::_1));
81}
82
88template <class InputRange, class Predicate>
89inline typename boost::range_iterator<InputRange>::type find_if_not(InputRange& range,
90 Predicate pred) {
91 return adobe::find_if_not(boost::begin(range), boost::end(range), pred);
92}
93
99template <class InputRange, class Predicate>
100inline typename boost::range_const_iterator<InputRange>::type find_if_not(const InputRange& range,
101 Predicate pred) {
102 return adobe::find_if_not(boost::begin(range), boost::end(range), pred);
103}
104
105/**************************************************************************************************/
106
110template <class InputIterator, class T>
111inline InputIterator find_not(InputIterator first, InputIterator last, const T& value) {
112 return std::find_if_not(first, last,
113 std::bind(std::equal_to<T>(), value, std::placeholders::_1));
114}
115
121template <class InputRange, class T>
122inline typename boost::range_iterator<InputRange>::type find_not(InputRange& range,
123 const T& value) {
124 return adobe::find_not(boost::begin(range), boost::end(range), value);
125}
126
132template <class InputRange, class T>
133inline typename boost::range_const_iterator<InputRange>::type find_not(const InputRange& range,
134 const T& value) {
135 return adobe::find_not(boost::begin(range), boost::end(range), value);
136}
137
138
143template <class InputRange, class T>
144inline typename boost::range_iterator<InputRange>::type find(InputRange& range, const T& value) {
145 return std::find(boost::begin(range), boost::end(range), value);
146}
147
153template <class InputRange, class T>
154inline typename boost::range_const_iterator<InputRange>::type find(const InputRange& range,
155 const T& value) {
156 return std::find(boost::begin(range), boost::end(range), value);
157}
158
164template <class InputIterator, class Predicate>
165inline InputIterator find_if(InputIterator first, InputIterator last, Predicate pred) {
166 return std::find_if(first, last, std::bind(pred, std::placeholders::_1));
167}
168
174template <class InputRange, class Predicate>
175inline typename boost::range_iterator<InputRange>::type find_if(InputRange& range, Predicate pred) {
176 return adobe::find_if(boost::begin(range), boost::end(range), pred);
177}
178
184template <class InputRange, class Predicate>
185inline typename boost::range_const_iterator<InputRange>::type find_if(const InputRange& range,
186 Predicate pred) {
187 return adobe::find_if(boost::begin(range), boost::end(range), pred);
188}
189
193
194template <typename I, // I models ForwardIterator
195 typename T>
196// T is value_type(I)
197std::pair<I, I> find_range(I f, I l, const T& x) {
198 f = std::find(f, l, x);
199 if (f != l)
200 l = find_not(boost::next(f), l, x);
201 return std::make_pair(f, l);
202}
203
207
208template <typename I, // I models ForwardIterator
209 typename P>
210// P models UnaryPredicate(value_type(I))
211std::pair<I, I> find_range_if(I f, I l, P p) {
212 f = adobe::find_if(f, l, p);
213 if (f != l)
214 l = adobe::find_if_not(boost::next(f), l, p);
215 return std::make_pair(f, l);
216}
217
223template <class ForwardRange1, class ForwardRange2>
224inline typename boost::range_iterator<ForwardRange1>::type find_end(ForwardRange1& range1,
225 const ForwardRange2& range2) {
226 return std::find_end(boost::begin(range1), boost::end(range1), boost::begin(range2),
227 boost::end(range2));
228}
229
235template <class ForwardRange1, class ForwardRange2>
236inline typename boost::range_const_iterator<ForwardRange1>::type
237find_end(const ForwardRange1& range1, const ForwardRange2& range2) {
238 return std::find_end(boost::begin(range1), boost::end(range1), boost::begin(range2),
239 boost::end(range2));
240}
241
247template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
248inline ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
249 ForwardIterator2 first2, ForwardIterator2 last2,
250 BinaryPredicate comp) {
251 return std::find_end(first1, last1, first2, last2,
252 std::bind(comp, std::placeholders::_1, std::placeholders::_2));
253}
254
260template <class ForwardRange1, class ForwardRange2, class BinaryPredicate>
261inline typename boost::range_iterator<ForwardRange1>::type
262find_end(ForwardRange1& range1, const ForwardRange2& range2, BinaryPredicate comp) {
263 return adobe::find_end(boost::begin(range1), boost::end(range1), boost::begin(range2),
264 boost::end(range2), comp);
265}
266
272template <class ForwardRange1, class ForwardRange2, class BinaryPredicate>
273inline typename boost::range_const_iterator<ForwardRange1>::type
274find_end(const ForwardRange1& range1, const ForwardRange2& range2, BinaryPredicate comp) {
275 return adobe::find_end(boost::begin(range1), boost::end(range1), boost::begin(range2),
276 boost::end(range2), comp);
277}
278
279#if 0
280
281// find_first_of is a bad algorithm. Use find_first_of_set until we provide a better predicate.
282
288template <class InputRange, class ForwardRange>
289inline typename boost::range_iterator<InputRange>::type
290find_first_of(InputRange& range1, const ForwardRange& range2)
291{
292 return std::find_first_of(boost::begin(range1), boost::end(range1),
293 boost::begin(range2), boost::end(range2));
294}
295
301template <class InputRange, class ForwardRange>
302inline typename boost::range_const_iterator<InputRange>::type
303find_first_of(const InputRange& range1, const ForwardRange& range2)
304{
305 return std::find_first_of(boost::begin(range1), boost::end(range1),
306 boost::begin(range2), boost::end(range2));
307}
308
314template <class InputIterator, class ForwardIterator, class BinaryPredicate>
315inline InputIterator find_first_of(InputIterator first1, InputIterator last1,
316 ForwardIterator first2, ForwardIterator last2,
317 BinaryPredicate comp)
318
319{
320 return std::find_first_of(first1, last1, first2, last2, std::bind(comp, std::placeholders::_1, std::placeholders::_2));
321}
322
328template <class InputRange, class ForwardRange, class BinaryPredicate>
329inline typename boost::range_iterator<InputRange>::type
330find_first_of(InputRange& range1, const ForwardRange& range2, BinaryPredicate comp)
331{
332 return adobe::find_first_of(boost::begin(range1), boost::end(range1),
333 boost::begin(range2), boost::end(range2),
334 comp);
335}
336
342template <class InputRange, class ForwardRange, class BinaryPredicate>
343inline typename boost::range_const_iterator<InputRange>::type
344find_first_of(const InputRange& range1, const ForwardRange& range2, BinaryPredicate comp)
345{
346 return adobe::find_first_of(boost::begin(range1), boost::end(range1),
347 boost::begin(range2), boost::end(range2),
348 comp);
349}
350
351#endif
352
358template <class ForwardRange>
359inline typename boost::range_iterator<ForwardRange>::type adjacent_find(ForwardRange& range) {
360 return std::adjacent_find(boost::begin(range), boost::end(range));
361}
362
368template <class ForwardRange>
369inline typename boost::range_const_iterator<ForwardRange>::type
370adjacent_find(const ForwardRange& range) {
371 return std::adjacent_find(boost::begin(range), boost::end(range));
372}
373
379template <class ForwardIterator, class BinaryPredicate>
380inline ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last,
381 BinaryPredicate pred) {
382 return std::adjacent_find(first, last,
383 std::bind(pred, std::placeholders::_1, std::placeholders::_2));
384}
385
391template <class ForwardRange, class BinaryPredicate>
392inline typename boost::range_iterator<ForwardRange>::type adjacent_find(ForwardRange& range,
393 BinaryPredicate pred) {
394 return adobe::adjacent_find(boost::begin(range), boost::end(range), pred);
395}
396
402template <class ForwardRange, class BinaryPredicate>
403inline typename boost::range_const_iterator<ForwardRange>::type
404adjacent_find(const ForwardRange& range, BinaryPredicate pred) {
405 return adobe::adjacent_find(boost::begin(range), boost::end(range), pred);
406}
407
408/**************************************************************************************************/
409
410} // namespace adobe
411
412/**************************************************************************************************/
413
414#endif
415
416/**************************************************************************************************/
InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pred)
find_if_not implementation
Definition find.hpp:79
InputIterator find_not(InputIterator first, InputIterator last, const T &value)
Definition find.hpp:111
boost::range_iterator< ForwardRange >::type adjacent_find(ForwardRange &range)
find implementation
Definition find.hpp:359
boost::range_iterator< ForwardRange1 >::type find_end(ForwardRange1 &range1, const ForwardRange2 &range2)
find implementation
Definition find.hpp:224
std::pair< I, I > find_range(I f, I l, const T &x)
Definition find.hpp:197
std::pair< I, I > find_range_if(I f, I l, P p)
Definition find.hpp:211
InputIterator find_if(InputIterator first, InputIterator last, Predicate pred)
find implementation
Definition find.hpp:165
boost::range_iterator< InputRange >::type find(InputRange &range, const T &value)
find implementation
Definition find.hpp:144