Chris@16: /* Chris@16: Copyright (c) Marshall Clow 2008-2012. Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: /// \file all_of.hpp Chris@16: /// \brief Test ranges to see if all elements match a value or predicate. Chris@16: /// \author Marshall Clow Chris@16: Chris@16: #ifndef BOOST_ALGORITHM_ALL_OF_HPP Chris@16: #define BOOST_ALGORITHM_ALL_OF_HPP Chris@16: Chris@16: #include // for std::all_of, if available Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace algorithm { Chris@16: Chris@16: /// \fn all_of ( InputIterator first, InputIterator last, Predicate p ) Chris@16: /// \return true if all elements in [first, last) satisfy the predicate 'p' Chris@16: /// \note returns true on an empty range Chris@16: /// Chris@16: /// \param first The start of the input sequence Chris@16: /// \param last One past the end of the input sequence Chris@16: /// \param p A predicate for testing the elements of the sequence Chris@16: /// Chris@16: /// \note This function is part of the C++2011 standard library. Chris@16: /// We will use the standard one if it is available, Chris@16: /// otherwise we have our own implementation. Chris@16: template Chris@16: bool all_of ( InputIterator first, InputIterator last, Predicate p ) Chris@16: { Chris@16: for ( ; first != last; ++first ) Chris@16: if ( !p(*first)) Chris@16: return false; Chris@16: return true; Chris@16: } Chris@16: Chris@16: /// \fn all_of ( const Range &r, Predicate p ) Chris@16: /// \return true if all elements in the range satisfy the predicate 'p' Chris@16: /// \note returns true on an empty range Chris@16: /// Chris@16: /// \param r The input range Chris@16: /// \param p A predicate for testing the elements of the range Chris@16: /// Chris@16: template Chris@16: bool all_of ( const Range &r, Predicate p ) Chris@16: { Chris@16: return boost::algorithm::all_of ( boost::begin (r), boost::end (r), p ); Chris@16: } Chris@16: Chris@16: /// \fn all_of_equal ( InputIterator first, InputIterator last, const T &val ) Chris@16: /// \return true if all elements in [first, last) are equal to 'val' Chris@16: /// \note returns true on an empty range Chris@16: /// Chris@16: /// \param first The start of the input sequence Chris@16: /// \param last One past the end of the input sequence Chris@16: /// \param val A value to compare against Chris@16: /// Chris@16: template Chris@16: bool all_of_equal ( InputIterator first, InputIterator last, const T &val ) Chris@16: { Chris@16: for ( ; first != last; ++first ) Chris@16: if ( val != *first ) Chris@16: return false; Chris@16: return true; Chris@16: } Chris@16: Chris@16: /// \fn all_of_equal ( const Range &r, const T &val ) Chris@16: /// \return true if all elements in the range are equal to 'val' Chris@16: /// \note returns true on an empty range Chris@16: /// Chris@16: /// \param r The input range Chris@16: /// \param val A value to compare against Chris@16: /// Chris@16: template Chris@16: bool all_of_equal ( const Range &r, const T &val ) Chris@16: { Chris@16: return boost::algorithm::all_of_equal ( boost::begin (r), boost::end (r), val ); Chris@16: } Chris@16: Chris@16: }} // namespace boost and algorithm Chris@16: Chris@16: #endif // BOOST_ALGORITHM_ALL_OF_HPP