1/*
2 Copyright (c) Marshall Clow 2008-2012.
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 For more information, see http://www.boost.org
8*/
9
10/// \file
11/// \brief Test ranges to see if any elements match a value or predicate.
12/// \author Marshall Clow
13
14#ifndef BOOST_ALGORITHM_ANY_OF_HPP
15#define BOOST_ALGORITHM_ANY_OF_HPP
16
17#include <algorithm> // for std::any_of, if available
18#include <boost/range/begin.hpp>
19#include <boost/range/end.hpp>
20
21namespace boost { namespace algorithm {
22
23/// \fn any_of ( InputIterator first, InputIterator last, Predicate p )
24/// \return true if any of the elements in [first, last) satisfy the predicate
25/// \note returns false on an empty range
26///
27/// \param first The start of the input sequence
28/// \param last One past the end of the input sequence
29/// \param p A predicate for testing the elements of the sequence
30///
31template<typename InputIterator, typename Predicate>
32bool any_of ( InputIterator first, InputIterator last, Predicate p )
33{
34 for ( ; first != last; ++first )
35 if ( p(*first))
36 return true;
37 return false;
38}
39
40/// \fn any_of ( const Range &r, Predicate p )
41/// \return true if any elements in the range satisfy the predicate 'p'
42/// \note returns false on an empty range
43///
44/// \param r The input range
45/// \param p A predicate for testing the elements of the range
46///
47template<typename Range, typename Predicate>
48bool any_of ( const Range &r, Predicate p )
49{
50 return boost::algorithm::any_of (boost::begin (r), boost::end (r), p);
51}
52
53/// \fn any_of_equal ( InputIterator first, InputIterator last, const V &val )
54/// \return true if any of the elements in [first, last) are equal to 'val'
55/// \note returns false on an empty range
56///
57/// \param first The start of the input sequence
58/// \param last One past the end of the input sequence
59/// \param val A value to compare against
60///
61template<typename InputIterator, typename V>
62bool any_of_equal ( InputIterator first, InputIterator last, const V &val )
63{
64 for ( ; first != last; ++first )
65 if ( val == *first )
66 return true;
67 return false;
68}
69
70/// \fn any_of_equal ( const Range &r, const V &val )
71/// \return true if any of the elements in the range are equal to 'val'
72/// \note returns false on an empty range
73///
74/// \param r The input range
75/// \param val A value to compare against
76///
77template<typename Range, typename V>
78bool any_of_equal ( const Range &r, const V &val )
79{
80 return boost::algorithm::any_of_equal (boost::begin (r), boost::end (r), val);
81}
82
83}} // namespace boost and algorithm
84
85#endif // BOOST_ALGORITHM_ANY_OF_HPP
86

source code of boost/boost/algorithm/cxx11/any_of.hpp