Fix the BinaryPredicate form of std::is_permutation to not rely on operator==

According to [1], forms 2 and 4 of std::is_permutation should use the passed in
binary predicate to compare elements. operator== should only be used for forms
1 and 3 which do not take a binary predicate.

This CL fixes forms 2 and 4 which relied on operator== for some comparisons.

[1] http://en.cppreference.com/w/cpp/algorithm/is_permutation

Patch by Thomas Anderson!

Differential Revision: https://reviews.llvm.org/D42518

llvm-svn: 323563
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 939b16233b20c745db4a762b1112fa071a08ef91
diff --git a/include/algorithm b/include/algorithm
index 3493428..9d2690d 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -1418,7 +1418,11 @@
     for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
     {
     //  Have we already counted the number of *__i in [f1, l1)?
-        if (find(__first1, __i, *__i) == __i) {
+        _ForwardIterator1 __match = __first1;
+        for (; __match != __i; ++__match)
+            if (__pred(*__match, *__i))
+                break;
+        if (__match == __i) {
             // Count number of *__i in [f2, l2)
             _D1 __c2 = 0;
             for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
@@ -1479,7 +1483,11 @@
     for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
     {
     //  Have we already counted the number of *__i in [f1, l1)?
-        if (find(__first1, __i, *__i) == __i) {
+        _ForwardIterator1 __match = __first1;
+        for (; __match != __i; ++__match)
+            if (__pred(*__match, *__i))
+                break;
+        if (__match == __i) {
             // Count number of *__i in [f2, l2)
             _D1 __c2 = 0;
             for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)