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
19namespace 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
30template< class SinglePassRange, class UnaryPredicate >
31inline BOOST_DEDUCED_TYPENAME disable_if<
32 is_const<SinglePassRange>,
33 BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type
34>::type
35find_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
42template< class SinglePassRange, class UnaryPredicate >
43inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type
44find_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
53template< range_return_value re, class SinglePassRange, class UnaryPredicate >
54inline BOOST_DEDUCED_TYPENAME disable_if<
55 is_const<SinglePassRange>,
56 BOOST_DEDUCED_TYPENAME range_return<SinglePassRange,re>::type
57>::type
58find_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
67template< range_return_value re, class SinglePassRange, class UnaryPredicate >
68inline BOOST_DEDUCED_TYPENAME range_return<const SinglePassRange,re>::type
69find_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
82