Chris@16: /* Chris@16: Copyright (c) Marshall Clow 2008-2012. Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt) Chris@16: */ Chris@16: Chris@16: /// \file mismatch.hpp Chris@16: /// \brief Find the first mismatched element in a sequence Chris@16: /// \author Marshall Clow Chris@16: Chris@16: #ifndef BOOST_ALGORITHM_MISMATCH_HPP Chris@16: #define BOOST_ALGORITHM_MISMATCH_HPP Chris@16: Chris@16: #include // for std::mismatch Chris@16: #include // for std::pair Chris@16: Chris@16: namespace boost { namespace algorithm { Chris@16: Chris@16: /// \fn mismatch ( InputIterator1 first1, InputIterator1 last1, Chris@16: /// InputIterator2 first2, InputIterator2 last2, Chris@16: /// BinaryPredicate pred ) Chris@16: /// \return a pair of iterators pointing to the first elements in the sequence that do not match Chris@16: /// Chris@16: /// \param first1 The start of the first range. Chris@16: /// \param last1 One past the end of the first range. Chris@16: /// \param first2 The start of the second range. Chris@16: /// \param last2 One past the end of the second range. Chris@16: /// \param pred A predicate for comparing the elements of the ranges Chris@16: template Chris@16: std::pair mismatch ( Chris@16: InputIterator1 first1, InputIterator1 last1, Chris@16: InputIterator2 first2, InputIterator2 last2, Chris@16: BinaryPredicate pred ) Chris@16: { Chris@16: for (; first1 != last1 && first2 != last2; ++first1, ++first2) Chris@16: if ( !pred ( *first1, *first2 )) Chris@16: break; Chris@16: return std::pair(first1, first2); Chris@16: } Chris@16: Chris@16: /// \fn mismatch ( InputIterator1 first1, InputIterator1 last1, Chris@16: /// InputIterator2 first2, InputIterator2 last2 ) Chris@16: /// \return a pair of iterators pointing to the first elements in the sequence that do not match Chris@16: /// Chris@16: /// \param first1 The start of the first range. Chris@16: /// \param last1 One past the end of the first range. Chris@16: /// \param first2 The start of the second range. Chris@16: /// \param last2 One past the end of the second range. Chris@16: template Chris@16: std::pair mismatch ( Chris@16: InputIterator1 first1, InputIterator1 last1, Chris@16: InputIterator2 first2, InputIterator2 last2 ) Chris@16: { Chris@16: for (; first1 != last1 && first2 != last2; ++first1, ++first2) Chris@16: if ( *first1 != *first2 ) Chris@16: break; Chris@16: return std::pair(first1, first2); Chris@16: } Chris@16: Chris@16: // There are already range-based versions of these. Chris@16: Chris@16: }} // namespace boost and algorithm Chris@16: Chris@16: #endif // BOOST_ALGORITHM_MISMATCH_HPP