完成mismatch

This commit is contained in:
邹晓航
2014-11-03 14:08:58 +08:00
parent a565015370
commit 671e2d059f

View File

@@ -7,6 +7,7 @@
#include "TypeTraits.h"
#include <cstring>
#include <utility>
namespace TinySTL{
//********* [fill] ********************
@@ -345,6 +346,27 @@ namespace TinySTL{
}
return n;
}
//********** [mismatch] ******************************
//********* [Algorithm Complexity: O(N)] ****************
template <class InputIterator1, class InputIterator2>
std::pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2){
for (; first1 != last1; ++first1, ++first2){
if (*first1 != *first2)
break;
}
return std::make_pair(first1, first2);
}
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
std::pair<InputIterator1, InputIterator2>
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);
}
}