1/*
2 Copyright (c) Marshall Clow 2008-2012.
3
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)
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 <algorithm> // for std::mismatch
16#include <utility> // for std::pair
17
18namespace boost { namespace algorithm {
19
20/// \fn mismatch ( InputIterator1 first1, InputIterator1 last1,
21/// InputIterator2 first2, InputIterator2 last2,
22/// BinaryPredicate pred )
23/// \return a pair of iterators pointing to the first elements in the sequence that do not match
24///
25/// \param first1 The start of the first range.
26/// \param last1 One past the end of the first range.
27/// \param first2 The start of the second range.
28/// \param last2 One past the end of the second range.
29/// \param pred A predicate for comparing the elements of the ranges
30template <class InputIterator1, class InputIterator2, class BinaryPredicate>
31std::pair<InputIterator1, InputIterator2> mismatch (
32 InputIterator1 first1, InputIterator1 last1,
33 InputIterator2 first2, InputIterator2 last2,
34 BinaryPredicate pred )
35{
36 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
37 if ( !pred ( *first1, *first2 ))
38 break;
39 return std::pair<InputIterator1, InputIterator2>(first1, first2);
40}
41
42/// \fn mismatch ( InputIterator1 first1, InputIterator1 last1,
43/// InputIterator2 first2, InputIterator2 last2 )
44/// \return a pair of iterators pointing to the first elements in the sequence that do not match
45///
46/// \param first1 The start of the first range.
47/// \param last1 One past the end of the first range.
48/// \param first2 The start of the second range.
49/// \param last2 One past the end of the second range.
50template <class InputIterator1, class InputIterator2>
51std::pair<InputIterator1, InputIterator2> mismatch (
52 InputIterator1 first1, InputIterator1 last1,
53 InputIterator2 first2, InputIterator2 last2 )
54{
55 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
56 if ( *first1 != *first2 )
57 break;
58 return std::pair<InputIterator1, InputIterator2>(first1, first2);
59}
60
61// There are already range-based versions of these.
62
63}} // namespace boost and algorithm
64
65#endif // BOOST_ALGORITHM_MISMATCH_HPP
66