1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
13 // size_type erase(const key_type& k);
23 #include "MinSequenceContainer.h"
24 #include "../helpers.h"
25 #include "test_macros.h"
26 #include "min_allocator.h"
28 template <class KeyContainer
, class ValueContainer
, class Compare
= std::less
<>>
30 using M
= std::flat_map
<int, char, Compare
, KeyContainer
, ValueContainer
>;
32 auto make
= [](std::initializer_list
<int> il
) {
39 M m
= make({1, 2, 3, 4, 5, 6, 7, 8});
40 ASSERT_SAME_TYPE(decltype(m
.erase(9)), typename
M::size_type
);
43 assert(m
== make({1, 2, 3, 4, 5, 6, 7, 8}));
46 assert(m
== make({1, 2, 3, 5, 6, 7, 8}));
49 assert(m
== make({2, 3, 5, 6, 7, 8}));
52 assert(m
== make({2, 3, 5, 6, 7}));
55 assert(m
== make({2, 5, 6, 7}));
58 assert(m
== make({2, 5, 6, 7}));
61 assert(m
== make({2, 5, 7}));
64 assert(m
== make({2, 5}));
67 assert(m
== make({5}));
73 int main(int, char**) {
74 test
<std::vector
<int>, std::vector
<char>>();
75 test
<std::vector
<int>, std::vector
<char>, std::greater
<>>();
76 test
<std::deque
<int>, std::vector
<char>>();
77 test
<MinSequenceContainer
<int>, MinSequenceContainer
<char>>();
78 test
<std::vector
<int, min_allocator
<int>>, std::vector
<char, min_allocator
<char>>>();
81 auto erase_function
= [](auto& m
, auto key_arg
) {
82 using Map
= std::decay_t
<decltype(m
)>;
83 using Key
= typename
Map::key_type
;
84 const Key key
{key_arg
};
87 test_erase_exception_guarantee(erase_function
);