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 Find the first mismatched element in a sequence
10 /// \author Marshall Clow
12 #ifndef BOOST_ALGORITHM_MISMATCH_HPP
13 #define BOOST_ALGORITHM_MISMATCH_HPP
15 #include <utility> // for std::pair
17 #include <boost/config.hpp>
19 namespace boost { namespace algorithm {
21 /// \fn mismatch ( InputIterator1 first1, InputIterator1 last1,
22 /// InputIterator2 first2, InputIterator2 last2,
23 /// BinaryPredicate pred )
24 /// \return a pair of iterators pointing to the first elements in the sequence that do not match
26 /// \param first1 The start of the first range.
27 /// \param last1 One past the end of the first range.
28 /// \param first2 The start of the second range.
29 /// \param last2 One past the end of the second range.
30 /// \param pred A predicate for comparing the elements of the ranges
31 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
32 BOOST_CXX14_CONSTEXPR std::pair<InputIterator1, InputIterator2> mismatch (
33 InputIterator1 first1, InputIterator1 last1,
34 InputIterator2 first2, InputIterator2 last2,
35 BinaryPredicate pred )
37 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
38 if ( !pred ( *first1, *first2 ))
40 return std::pair<InputIterator1, InputIterator2>(first1, first2);
43 /// \fn mismatch ( InputIterator1 first1, InputIterator1 last1,
44 /// InputIterator2 first2, InputIterator2 last2 )
45 /// \return a pair of iterators pointing to the first elements in the sequence that do not match
47 /// \param first1 The start of the first range.
48 /// \param last1 One past the end of the first range.
49 /// \param first2 The start of the second range.
50 /// \param last2 One past the end of the second range.
51 template <class InputIterator1, class InputIterator2>
52 BOOST_CXX14_CONSTEXPR std::pair<InputIterator1, InputIterator2> mismatch (
53 InputIterator1 first1, InputIterator1 last1,
54 InputIterator2 first2, InputIterator2 last2 )
56 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
57 if ( *first1 != *first2 )
59 return std::pair<InputIterator1, InputIterator2>(first1, first2);
62 // There are already range-based versions of these.
64 }} // namespace boost and algorithm
66 #endif // BOOST_ALGORITHM_MISMATCH_HPP