2 Copyright (c) Marshall Clow 2008-2012.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.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 namespace boost { namespace algorithm {
19 /// \fn mismatch ( InputIterator1 first1, InputIterator1 last1,
20 /// InputIterator2 first2, InputIterator2 last2,
21 /// BinaryPredicate pred )
22 /// \return a pair of iterators pointing to the first elements in the sequence that do not match
24 /// \param first1 The start of the first range.
25 /// \param last1 One past the end of the first range.
26 /// \param first2 The start of the second range.
27 /// \param last2 One past the end of the second range.
28 /// \param pred A predicate for comparing the elements of the ranges
29 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
30 std::pair<InputIterator1, InputIterator2> mismatch (
31 InputIterator1 first1, InputIterator1 last1,
32 InputIterator2 first2, InputIterator2 last2,
33 BinaryPredicate pred )
35 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
36 if ( !pred ( *first1, *first2 ))
38 return std::pair<InputIterator1, InputIterator2>(first1, first2);
41 /// \fn mismatch ( InputIterator1 first1, InputIterator1 last1,
42 /// InputIterator2 first2, InputIterator2 last2 )
43 /// \return a pair of iterators pointing to the first elements in the sequence that do not match
45 /// \param first1 The start of the first range.
46 /// \param last1 One past the end of the first range.
47 /// \param first2 The start of the second range.
48 /// \param last2 One past the end of the second range.
49 template <class InputIterator1, class InputIterator2>
50 std::pair<InputIterator1, InputIterator2> mismatch (
51 InputIterator1 first1, InputIterator1 last1,
52 InputIterator2 first2, InputIterator2 last2 )
54 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
55 if ( *first1 != *first2 )
57 return std::pair<InputIterator1, InputIterator2>(first1, first2);
60 // There are already range-based versions of these.
62 }} // namespace boost and algorithm
64 #endif // BOOST_ALGORITHM_MISMATCH_HPP