Back to home page

EIC code displayed by LXR

 
 

    


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

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  equal.hpp
0009 /// \brief Test ranges to if they are equal
0010 /// \author Marshall Clow
0011 
0012 #ifndef BOOST_ALGORITHM_EQUAL_HPP
0013 #define BOOST_ALGORITHM_EQUAL_HPP
0014 
0015 #include <iterator>
0016 
0017 #include <boost/config.hpp>
0018 
0019 namespace boost { namespace algorithm {
0020 
0021 namespace detail {
0022 
0023     template <class T1, class T2>
0024     struct eq {
0025         BOOST_CONSTEXPR bool operator () ( const T1& v1, const T2& v2 ) const { return v1 == v2 ;}
0026         };
0027     
0028     template <class RandomAccessIterator1, class RandomAccessIterator2, class BinaryPredicate>
0029     BOOST_CXX14_CONSTEXPR
0030     bool equal ( RandomAccessIterator1 first1, RandomAccessIterator1 last1, 
0031                  RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
0032                  std::random_access_iterator_tag, std::random_access_iterator_tag )
0033     {
0034     //  Random-access iterators let is check the sizes in constant time
0035         if ( std::distance ( first1, last1 ) != std::distance ( first2, last2 ))
0036             return false;
0037 
0038     //  std::equal
0039         for (; first1 != last1; ++first1, ++first2)
0040             if (!pred(*first1, *first2))
0041                 return false;
0042         return true;
0043     }
0044 
0045     template <class InputIterator1, class InputIterator2, class BinaryPredicate>
0046     BOOST_CXX14_CONSTEXPR
0047     bool equal ( InputIterator1 first1, InputIterator1 last1, 
0048                  InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred,
0049                  std::input_iterator_tag, std::input_iterator_tag )
0050     {
0051     for (; first1 != last1 && first2 != last2; ++first1, ++first2 )
0052         if ( !pred(*first1, *first2 ))
0053             return false;
0054 
0055     return first1 == last1 && first2 == last2;
0056     }
0057 }
0058 
0059 /// \fn equal ( InputIterator1 first1, InputIterator1 last1, 
0060 ///             InputIterator2 first2, InputIterator2 last2,
0061 ///             BinaryPredicate pred )
0062 /// \return true if all elements in the two ranges are equal
0063 /// 
0064 /// \param first1    The start of the first range.
0065 /// \param last1     One past the end of the first range.
0066 /// \param first2    The start of the second range.
0067 /// \param last2     One past the end of the second range.
0068 /// \param pred      A predicate for comparing the elements of the ranges
0069 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
0070 BOOST_CXX14_CONSTEXPR
0071 bool equal ( InputIterator1 first1, InputIterator1 last1, 
0072              InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred )
0073 {
0074     return boost::algorithm::detail::equal ( 
0075         first1, last1, first2, last2, pred,
0076         typename std::iterator_traits<InputIterator1>::iterator_category (),
0077         typename std::iterator_traits<InputIterator2>::iterator_category ());
0078 }
0079 
0080 /// \fn equal ( InputIterator1 first1, InputIterator1 last1, 
0081 ///             InputIterator2 first2, InputIterator2 last2 )
0082 /// \return true if all elements in the two ranges are equal
0083 /// 
0084 /// \param first1    The start of the first range.
0085 /// \param last1     One past the end of the first range.
0086 /// \param first2    The start of the second range.
0087 /// \param last2     One past the end of the second range.
0088 template <class InputIterator1, class InputIterator2>
0089 BOOST_CXX14_CONSTEXPR
0090 bool equal ( InputIterator1 first1, InputIterator1 last1, 
0091              InputIterator2 first2, InputIterator2 last2 )
0092 {
0093     return boost::algorithm::detail::equal (
0094         first1, last1, first2, last2,
0095         boost::algorithm::detail::eq<
0096             typename std::iterator_traits<InputIterator1>::value_type,
0097             typename std::iterator_traits<InputIterator2>::value_type> (),
0098         typename std::iterator_traits<InputIterator1>::iterator_category (),
0099         typename std::iterator_traits<InputIterator2>::iterator_category ());
0100 }
0101 
0102 //  There are already range-based versions of these.
0103 
0104 }} // namespace boost and algorithm
0105 
0106 #endif // BOOST_ALGORITHM_EQUAL_HPP