2 Copyright (c) Marshall Clow 2008-2012.
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)
9 /// \brief Test ranges to if they are equal
10 /// \author Marshall Clow
12 #ifndef BOOST_ALGORITHM_EQUAL_HPP
13 #define BOOST_ALGORITHM_EQUAL_HPP
17 #include <boost/config.hpp>
19 namespace boost { namespace algorithm {
23 template <class T1, class T2>
25 BOOST_CONSTEXPR bool operator () ( const T1& v1, const T2& v2 ) const { return v1 == v2 ;}
28 template <class RandomAccessIterator1, class RandomAccessIterator2, class BinaryPredicate>
30 bool equal ( RandomAccessIterator1 first1, RandomAccessIterator1 last1,
31 RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
32 std::random_access_iterator_tag, std::random_access_iterator_tag )
34 // Random-access iterators let is check the sizes in constant time
35 if ( std::distance ( first1, last1 ) != std::distance ( first2, last2 ))
39 for (; first1 != last1; ++first1, ++first2)
40 if (!pred(*first1, *first2))
45 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
47 bool equal ( InputIterator1 first1, InputIterator1 last1,
48 InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred,
49 std::input_iterator_tag, std::input_iterator_tag )
51 for (; first1 != last1 && first2 != last2; ++first1, ++first2 )
52 if ( !pred(*first1, *first2 ))
55 return first1 == last1 && first2 == last2;
59 /// \fn equal ( InputIterator1 first1, InputIterator1 last1,
60 /// InputIterator2 first2, InputIterator2 last2,
61 /// BinaryPredicate pred )
62 /// \return true if all elements in the two ranges are equal
64 /// \param first1 The start of the first range.
65 /// \param last1 One past the end of the first range.
66 /// \param first2 The start of the second range.
67 /// \param last2 One past the end of the second range.
68 /// \param pred A predicate for comparing the elements of the ranges
69 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
71 bool equal ( InputIterator1 first1, InputIterator1 last1,
72 InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred )
74 return boost::algorithm::detail::equal (
75 first1, last1, first2, last2, pred,
76 typename std::iterator_traits<InputIterator1>::iterator_category (),
77 typename std::iterator_traits<InputIterator2>::iterator_category ());
80 /// \fn equal ( InputIterator1 first1, InputIterator1 last1,
81 /// InputIterator2 first2, InputIterator2 last2 )
82 /// \return true if all elements in the two ranges are equal
84 /// \param first1 The start of the first range.
85 /// \param last1 One past the end of the first range.
86 /// \param first2 The start of the second range.
87 /// \param last2 One past the end of the second range.
88 template <class InputIterator1, class InputIterator2>
90 bool equal ( InputIterator1 first1, InputIterator1 last1,
91 InputIterator2 first2, InputIterator2 last2 )
93 return boost::algorithm::detail::equal (
94 first1, last1, first2, last2,
95 boost::algorithm::detail::eq<
96 typename std::iterator_traits<InputIterator1>::value_type,
97 typename std::iterator_traits<InputIterator2>::value_type> (),
98 typename std::iterator_traits<InputIterator1>::iterator_category (),
99 typename std::iterator_traits<InputIterator2>::iterator_category ());
102 // There are already range-based versions of these.
104 }} // namespace boost and algorithm
106 #endif // BOOST_ALGORITHM_EQUAL_HPP