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 
0008 /// \file  all_of.hpp
0009 /// \brief Test ranges to see if all elements match a value or predicate.
0010 /// \author Marshall Clow
0011 
0012 #ifndef BOOST_ALGORITHM_ALL_OF_HPP
0013 #define BOOST_ALGORITHM_ALL_OF_HPP
0014 
0015 #include <boost/config.hpp>
0016 #include <boost/range/begin.hpp>
0017 #include <boost/range/end.hpp>
0018 
0019 namespace boost { namespace algorithm {
0020 
0021 /// \fn all_of ( InputIterator first, InputIterator last, Predicate p )
0022 /// \return true if all elements in [first, last) satisfy the predicate 'p'
0023 /// \note returns true on an empty range
0024 /// 
0025 /// \param first The start of the input sequence
0026 /// \param last  One past the end of the input sequence
0027 /// \param p     A predicate for testing the elements of the sequence
0028 ///
0029 /// \note           This function is part of the C++2011 standard library.
0030 template<typename InputIterator, typename Predicate> 
0031 BOOST_CXX14_CONSTEXPR bool all_of ( InputIterator first, InputIterator last, Predicate p )
0032 {
0033     for ( ; first != last; ++first )
0034         if ( !p(*first)) 
0035             return false;
0036     return true; 
0037 } 
0038 
0039 /// \fn all_of ( const Range &r, Predicate p )
0040 /// \return true if all elements in the range satisfy the predicate 'p'
0041 /// \note returns true on an empty range
0042 /// 
0043 /// \param r    The input range
0044 /// \param p    A predicate for testing the elements of the range
0045 ///
0046 template<typename Range, typename Predicate> 
0047 BOOST_CXX14_CONSTEXPR bool all_of ( const Range &r, Predicate p )
0048 {
0049     return boost::algorithm::all_of ( boost::begin (r), boost::end (r), p );
0050 } 
0051 
0052 /// \fn all_of_equal ( InputIterator first, InputIterator last, const T &val )
0053 /// \return true if all elements in [first, last) are equal to 'val'
0054 /// \note returns true on an empty range
0055 /// 
0056 /// \param first The start of the input sequence
0057 /// \param last  One past the end of the input sequence
0058 /// \param val   A value to compare against
0059 ///
0060 template<typename InputIterator, typename T> 
0061 BOOST_CXX14_CONSTEXPR bool all_of_equal ( InputIterator first, InputIterator last, const T &val )
0062 {
0063     for ( ; first != last; ++first )
0064     if ( val != *first ) 
0065         return false;
0066     return true; 
0067 } 
0068 
0069 /// \fn all_of_equal ( const Range &r, const T &val )
0070 /// \return true if all elements in the range are equal to 'val'
0071 /// \note returns true on an empty range
0072 /// 
0073 /// \param r    The input range
0074 /// \param val  A value to compare against
0075 ///
0076 template<typename Range, typename T> 
0077 BOOST_CXX14_CONSTEXPR bool all_of_equal ( const Range &r, const T &val ) 
0078 {
0079     return boost::algorithm::all_of_equal ( boost::begin (r), boost::end (r), val );
0080 } 
0081 
0082 }} // namespace boost and algorithm
0083 
0084 #endif // BOOST_ALGORITHM_ALL_OF_HPP