]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc
libstdc++: Call predicate with non-const values in std::erase_if [PR107850]
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_map / erasure.cc
index e6018186bf28a7bcb2b4d390c9a4a27d10315e5b..8392e538ac7509e53da7afa36a0975c99a663c8b 100644 (file)
@@ -61,11 +61,24 @@ test02()
   VERIFY( num == 4 );
 }
 
+void
+test_pr107850()
+{
+  // Predicate only callable as non-const and only accepts non-const argument.
+  struct Pred { bool operator()(std::pair<const int, int>&) { return false; } };
+  const Pred pred; // erase_if parameter is passed by value, so non-const.
+  std::unordered_map<int, int> m;
+  std::erase_if(m, pred);
+  std::unordered_multimap<int, int> mm;
+  std::erase_if(mm, pred);
+}
+
 int
 main()
 {
   test01();
   test02();
+  test_pr107850();
 
   return 0;
 }