]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright Neil Groves 2009. Use, modification and |
2 | // distribution is subject to the Boost Software License, Version | |
3 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | // | |
6 | // | |
7 | // For more information, see http://www.boost.org/libs/range/ | |
8 | // | |
9 | #ifndef BOOST_RANGE_ALGORITHM_FIND_IF_HPP_INCLUDED | |
10 | #define BOOST_RANGE_ALGORITHM_FIND_IF_HPP_INCLUDED | |
11 | ||
12 | #include <boost/concept_check.hpp> | |
13 | #include <boost/range/begin.hpp> | |
14 | #include <boost/range/end.hpp> | |
15 | #include <boost/range/concepts.hpp> | |
16 | #include <boost/range/detail/range_return.hpp> | |
17 | #include <algorithm> | |
18 | ||
19 | namespace boost | |
20 | { | |
21 | namespace range | |
22 | { | |
23 | ||
24 | /// \brief template function find_if | |
25 | /// | |
26 | /// range-based version of the find_if std algorithm | |
27 | /// | |
28 | /// \pre SinglePassRange is a model of the SinglePassRangeConcept | |
29 | /// \pre UnaryPredicate is a model of the UnaryPredicateConcept | |
30 | template< class SinglePassRange, class UnaryPredicate > | |
31 | inline BOOST_DEDUCED_TYPENAME disable_if< | |
32 | is_const<SinglePassRange>, | |
33 | BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type | |
34 | >::type | |
35 | find_if( SinglePassRange& rng, UnaryPredicate pred ) | |
36 | { | |
37 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> )); | |
38 | return std::find_if(boost::begin(rng), boost::end(rng), pred); | |
39 | } | |
40 | ||
41 | /// \overload | |
42 | template< class SinglePassRange, class UnaryPredicate > | |
43 | inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type | |
44 | find_if( const SinglePassRange& rng, UnaryPredicate pred ) | |
45 | { | |
46 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> )); | |
47 | return std::find_if(boost::begin(rng), boost::end(rng), pred); | |
48 | } | |
49 | ||
50 | // range_return overloads | |
51 | ||
52 | /// \overload | |
53 | template< range_return_value re, class SinglePassRange, class UnaryPredicate > | |
54 | inline BOOST_DEDUCED_TYPENAME disable_if< | |
55 | is_const<SinglePassRange>, | |
56 | BOOST_DEDUCED_TYPENAME range_return<SinglePassRange,re>::type | |
57 | >::type | |
58 | find_if( SinglePassRange& rng, UnaryPredicate pred ) | |
59 | { | |
60 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> )); | |
61 | return range_return<SinglePassRange,re>:: | |
62 | pack(std::find_if(boost::begin(rng), boost::end(rng), pred), | |
63 | rng); | |
64 | } | |
65 | ||
66 | /// \overload | |
67 | template< range_return_value re, class SinglePassRange, class UnaryPredicate > | |
68 | inline BOOST_DEDUCED_TYPENAME range_return<const SinglePassRange,re>::type | |
69 | find_if( const SinglePassRange& rng, UnaryPredicate pred ) | |
70 | { | |
71 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> )); | |
72 | return range_return<const SinglePassRange,re>:: | |
73 | pack(std::find_if(boost::begin(rng), boost::end(rng), pred), | |
74 | rng); | |
75 | } | |
76 | ||
77 | } // namespace range | |
78 | using range::find_if; | |
79 | } // namespace boost | |
80 | ||
81 | #endif // include guard |