summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers/associative/set
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2018-12-14 18:49:35 +0000
committerMarshall Clow <mclow.lists@gmail.com>2018-12-14 18:49:35 +0000
commitf60c63c090114a6b5f0ba0a7aacd67e6c92920e7 (patch)
tree17e10b3f0bbd3a373498bbe621f9036bdd176e32 /libcxx/test/std/containers/associative/set
parentb7e2d6e4931b88fc5c84358a1fa7a9d3dffbecbc (diff)
downloadbcm5719-llvm-f60c63c090114a6b5f0ba0a7aacd67e6c92920e7.tar.gz
bcm5719-llvm-f60c63c090114a6b5f0ba0a7aacd67e6c92920e7.zip
Implement P1209 - Adopt Consistent Container Erasure from Library Fundamentals 2 for C++20. Reviewed as https://reviews.llvm.org/D55532
llvm-svn: 349178
Diffstat (limited to 'libcxx/test/std/containers/associative/set')
-rw-r--r--libcxx/test/std/containers/associative/set/set.erasure/erase_if.pass.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/associative/set/set.erasure/erase_if.pass.cpp b/libcxx/test/std/containers/associative/set/set.erasure/erase_if.pass.cpp
new file mode 100644
index 00000000000..a55a38c2d56
--- /dev/null
+++ b/libcxx/test/std/containers/associative/set/set.erasure/erase_if.pass.cpp
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <set>
+
+// template <class T, class Compare, class Allocator, class Predicate>
+// void erase_if(set<T, Compare, Allocator>& c, Predicate pred);
+
+#include <set>
+
+#include "test_macros.h"
+#include "test_allocator.h"
+#include "min_allocator.h"
+
+template <class S, class Pred>
+void
+test0(S s, Pred p, S expected)
+{
+ ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p)));
+ std::erase_if(s, p);
+ assert(s == expected);
+}
+
+template <typename S>
+void test()
+{
+ auto is1 = [](auto v) { return v == 1;};
+ auto is2 = [](auto v) { return v == 2;};
+ auto is3 = [](auto v) { return v == 3;};
+ auto is4 = [](auto v) { return v == 4;};
+ auto True = [](auto) { return true; };
+ auto False = [](auto) { return false; };
+
+ test0(S(), is1, S());
+
+ test0(S({1}), is1, S());
+ test0(S({1}), is2, S({1}));
+
+ test0(S({1,2}), is1, S({2}));
+ test0(S({1,2}), is2, S({1}));
+ test0(S({1,2}), is3, S({1,2}));
+
+ test0(S({1,2,3}), is1, S({2,3}));
+ test0(S({1,2,3}), is2, S({1,3}));
+ test0(S({1,2,3}), is3, S({1,2}));
+ test0(S({1,2,3}), is4, S({1,2,3}));
+
+ test0(S({1,2,3}), True, S());
+ test0(S({1,2,3}), False, S({1,2,3}));
+}
+
+int main()
+{
+ test<std::set<int>>();
+ test<std::set<int, std::less<int>, min_allocator<int>>> ();
+ test<std::set<int, std::less<int>, test_allocator<int>>> ();
+
+ test<std::set<long>>();
+ test<std::set<double>>();
+}
OpenPOWER on IntegriCloud