完成mismatch
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "TypeTraits.h"
|
#include "TypeTraits.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace TinySTL{
|
namespace TinySTL{
|
||||||
//********* [fill] ********************
|
//********* [fill] ********************
|
||||||
@@ -345,6 +346,27 @@ namespace TinySTL{
|
|||||||
}
|
}
|
||||||
return n;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user