Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:22

0001 /* 
0002    Copyright (c) Marshall Clow 2008-2012.
0003 
0004    Distributed under the Boost Software License, Version 1.0. (See accompanying
0005    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007     For more information, see http://www.boost.org
0008 */
0009 
0010 /// \file
0011 /// \brief Test ranges to see if any elements match a value or predicate.
0012 /// \author Marshall Clow
0013 
0014 #ifndef BOOST_ALGORITHM_ANY_OF_HPP
0015 #define BOOST_ALGORITHM_ANY_OF_HPP
0016 
0017 #include <boost/config.hpp>
0018 #include <boost/range/begin.hpp>
0019 #include <boost/range/end.hpp>
0020 
0021 namespace boost { namespace algorithm {
0022 
0023 /// \fn any_of ( InputIterator first, InputIterator last, Predicate p )
0024 /// \return true if any of the elements in [first, last) satisfy the predicate
0025 /// \note returns false on an empty range
0026 /// 
0027 /// \param first The start of the input sequence
0028 /// \param last  One past the end of the input sequence
0029 /// \param p     A predicate for testing the elements of the sequence
0030 ///
0031 template<typename InputIterator, typename Predicate> 
0032 BOOST_CXX14_CONSTEXPR bool any_of ( InputIterator first, InputIterator last, Predicate p ) 
0033 {
0034     for ( ; first != last; ++first )
0035         if ( p(*first)) 
0036             return true;
0037     return false; 
0038 } 
0039 
0040 /// \fn any_of ( const Range &r, Predicate p )
0041 /// \return true if any elements in the range satisfy the predicate 'p'
0042 /// \note returns false on an empty range
0043 /// 
0044 /// \param r    The input range
0045 /// \param p    A predicate for testing the elements of the range
0046 ///
0047 template<typename Range, typename Predicate> 
0048 BOOST_CXX14_CONSTEXPR bool any_of ( const Range &r, Predicate p )
0049 {
0050     return boost::algorithm::any_of (boost::begin (r), boost::end (r), p);
0051 } 
0052 
0053 /// \fn any_of_equal ( InputIterator first, InputIterator last, const V &val )
0054 /// \return true if any of the elements in [first, last) are equal to 'val'
0055 /// \note returns false on an empty range
0056 /// 
0057 /// \param first The start of the input sequence
0058 /// \param last  One past the end of the input sequence
0059 /// \param val   A value to compare against
0060 ///
0061 template<typename InputIterator, typename V> 
0062 BOOST_CXX14_CONSTEXPR bool any_of_equal ( InputIterator first, InputIterator last, const V &val ) 
0063 {
0064     for ( ; first != last; ++first )
0065         if ( val == *first )
0066             return true;
0067     return false; 
0068 } 
0069 
0070 /// \fn any_of_equal ( const Range &r, const V &val )
0071 /// \return true if any of the elements in the range are equal to 'val'
0072 /// \note returns false on an empty range
0073 /// 
0074 /// \param r     The input range
0075 /// \param val   A value to compare against
0076 ///
0077 template<typename Range, typename V> 
0078 BOOST_CXX14_CONSTEXPR bool any_of_equal ( const Range &r, const V &val ) 
0079 {
0080     return boost::algorithm::any_of_equal (boost::begin (r), boost::end (r), val);
0081 }
0082 
0083 }} // namespace boost and algorithm
0084 
0085 #endif // BOOST_ALGORITHM_ANY_OF_HPP