From 671e2d059f753bb01b447d7e8b56b31d1a5d96f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Mon, 3 Nov 2014 14:08:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90mismatch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Algorithm.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/TinySTL/Algorithm.h b/TinySTL/Algorithm.h index 1007f85..72c4a48 100644 --- a/TinySTL/Algorithm.h +++ b/TinySTL/Algorithm.h @@ -7,6 +7,7 @@ #include "TypeTraits.h" #include +#include namespace TinySTL{ //********* [fill] ******************** @@ -345,6 +346,27 @@ namespace TinySTL{ } return n; } + //********** [mismatch] ****************************** + //********* [Algorithm Complexity: O(N)] **************** + template + std::pair + mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2){ + for (; first1 != last1; ++first1, ++first2){ + if (*first1 != *first2) + break; + } + return std::make_pair(first1, first2); + } + template + std::pair + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred){ + for (; first1 != last1; ++first1, ++first2){ + if (!pred(*first1, *first2)) + break; + } + return std::make_pair(first1, first2); + } }