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