diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2018-01-26 21:23:27 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2018-01-26 21:23:27 +0000 |
commit | 939b16233b20c745db4a762b1112fa071a08ef91 (patch) | |
tree | 8b5902db8605718b9e3229957cbce91dad76b8b7 /libcxx/test/std/algorithms/alg.nonmodifying | |
parent | d4273abb69e487883a612d49025dda2fb40322cd (diff) | |
download | bcm5719-llvm-939b16233b20c745db4a762b1112fa071a08ef91.tar.gz bcm5719-llvm-939b16233b20c745db4a762b1112fa071a08ef91.zip |
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
Diffstat (limited to 'libcxx/test/std/algorithms/alg.nonmodifying')
-rw-r--r-- | libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp index 6c40ce368db..12bd938d296 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp @@ -738,6 +738,30 @@ int main() std::equal_to<const int>()) == false); #endif } + { + struct S { + S(int i) : i_(i) {} + bool operator==(const S& other) = delete; + int i_; + }; + struct eq { + bool operator()(const S& a, const S&b) { return a.i_ == b.i_; } + }; + const S a[] = {S(0), S(1)}; + const S b[] = {S(1), S(0)}; + const unsigned sa = sizeof(a)/sizeof(a[0]); + assert(std::is_permutation(forward_iterator<const S*>(a), + forward_iterator<const S*>(a + sa), + forward_iterator<const S*>(b), + eq())); +#if TEST_STD_VER >= 14 + assert(std::is_permutation(forward_iterator<const S*>(a), + forward_iterator<const S*>(a + sa), + forward_iterator<const S*>(b), + forward_iterator<const S*>(b + sa), + eq())); +#endif + } #if TEST_STD_VER > 17 static_assert(test_constexpr()); |