1/*
2 Copyright (c) Marshall Clow 2008-2012.
3
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)
6*/
7
8/// \file mismatch.hpp
9/// \brief Find the first mismatched element in a sequence
10/// \author Marshall Clow
11
12#ifndef BOOST_ALGORITHM_MISMATCH_HPP
13#define BOOST_ALGORITHM_MISMATCH_HPP
14
15#include <utility> // for std::pair
16
17#include <boost/config.hpp>
18
19namespace boost { namespace algorithm {
20
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
25///
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
31template <class InputIterator1, class InputIterator2, class BinaryPredicate>
32BOOST_CXX14_CONSTEXPR std::pair<InputIterator1, InputIterator2> mismatch (
33 InputIterator1 first1, InputIterator1 last1,
34 InputIterator2 first2, InputIterator2 last2,
35 BinaryPredicate pred )
36{
37 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
38 if ( !pred ( *first1, *first2 ))
39 break;
40 return std::pair<InputIterator1, InputIterator2>(first1, first2);
41}
42
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
46///
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.
51template <class InputIterator1, class InputIterator2>
52BOOST_CXX14_CONSTEXPR std::pair<InputIterator1, InputIterator2> mismatch (
53 InputIterator1 first1, InputIterator1 last1,
54 InputIterator2 first2, InputIterator2 last2 )
55{
56 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
57 if ( *first1 != *first2 )
58 break;
59 return std::pair<InputIterator1, InputIterator2>(first1, first2);
60}
61
62// There are already range-based versions of these.
63
64}} // namespace boost and algorithm
65
66#endif // BOOST_ALGORITHM_MISMATCH_HPP
67

source code of boost/libs/algorithm/include/boost/algorithm/cxx14/mismatch.hpp