//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 // // class flat_multimap // template // typename flat_multimap::size_type // erase_if(flat_multimap& c, Predicate pred); #include #include #include #include #include #include "test_macros.h" #include "test_allocator.h" #include "min_allocator.h" // Verify that `flat_multimap` (like `multimap`) does NOT support std::erase. // template concept HasStdErase = requires(S& s, typename S::value_type x) { std::erase(s, x); }; static_assert(HasStdErase>); static_assert(!HasStdErase>); template constexpr M make(std::initializer_list vals) { M ret; for (int v : vals) { ret.emplace(static_cast(v), static_cast(v + 10)); } return ret; } template constexpr void test0(std::initializer_list vals, Pred p, std::initializer_list expected, std::size_t expected_erased_count) { M s = make(vals); ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p))); assert(expected_erased_count == std::erase_if(s, p)); assert(s == make(expected)); } template constexpr void test() { // Test all the plausible signatures for this predicate. auto is1 = [](typename S::const_reference v) { return v.first == 1; }; auto is2 = [](typename S::value_type v) { return v.first == 2; }; auto is3 = [](const typename S::value_type& v) { return v.first == 3; }; auto is4 = [](auto v) { return v.first == 4; }; auto True = [](const auto&) { return true; }; auto False = [](auto&&) { return false; }; test0({}, is1, {}, 0); test0({1}, is1, {}, 1); test0({1, 1}, is1, {}, 2); test0({1, 1}, is2, {1, 1}, 0); test0({1, 2}, is1, {2}, 1); test0({1, 2}, is2, {1}, 1); test0({1, 2, 2, 2}, is2, {1}, 3); test0({1, 2, 2, 2}, is3, {1, 2, 2, 2}, 0); test0({1, 1, 2, 2, 3, 3}, is1, {2, 2, 3, 3}, 2); test0({1, 1, 2, 2, 3, 3}, is2, {1, 1, 3, 3}, 2); test0({1, 1, 2, 2, 3, 3}, is3, {1, 1, 2, 2}, 2); test0({1, 1, 2, 2, 3, 3}, is4, {1, 1, 2, 2, 3, 3}, 0); test0({1, 2, 2, 3, 3, 3}, True, {}, 6); test0({1, 2, 2, 3, 3, 3}, False, {1, 2, 2, 3, 3, 3}, 0); } constexpr bool test() { test>(); test, std::vector>, std::vector>>>(); test, std::vector>>>(); #ifndef __cpp_lib_constexpr_deque if (!TEST_IS_CONSTANT_EVALUATED) #endif { test, std::deque>>>(); test, std::deque>>>(); } test>(); test>(); return true; } int main(int, char**) { test(); #if TEST_STD_VER >= 26 static_assert(test()); #endif return 0; }