1 | //===----------------------------------------------------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
10 | |
11 | // <flat_map> |
12 | |
13 | // class flat_multimap |
14 | |
15 | // size_type size() const noexcept; |
16 | |
17 | #include <cassert> |
18 | #include <deque> |
19 | #include <flat_map> |
20 | #include <functional> |
21 | #include <vector> |
22 | |
23 | #include "MinSequenceContainer.h" |
24 | #include "test_macros.h" |
25 | #include "min_allocator.h" |
26 | |
27 | template <class KeyContainer, class ValueContainer> |
28 | void test() { |
29 | using M = std::flat_multimap<int, char, std::less<int>, KeyContainer, ValueContainer>; |
30 | { |
31 | const M m = {{1, 'a'}, {1, 'b'}, {4, 'd'}, {5, 'e'}, {5, 'h'}}; |
32 | ASSERT_SAME_TYPE(decltype(m.size()), std::size_t); |
33 | ASSERT_NOEXCEPT(m.size()); |
34 | assert(m.size() == 5); |
35 | } |
36 | { |
37 | const M m = {{1, 'a'}}; |
38 | ASSERT_SAME_TYPE(decltype(m.size()), std::size_t); |
39 | ASSERT_NOEXCEPT(m.size()); |
40 | assert(m.size() == 1); |
41 | } |
42 | { |
43 | const M m; |
44 | ASSERT_SAME_TYPE(decltype(m.size()), std::size_t); |
45 | ASSERT_NOEXCEPT(m.size()); |
46 | assert(m.size() == 0); |
47 | } |
48 | { |
49 | M m; |
50 | std::size_t s = 1000; |
51 | for (auto i = 0u; i < s; ++i) { |
52 | m.emplace(i, 'a'); |
53 | } |
54 | for (auto i = 0u; i < s; ++i) { |
55 | m.emplace(i, 'b'); |
56 | } |
57 | ASSERT_SAME_TYPE(decltype(m.size()), std::size_t); |
58 | ASSERT_NOEXCEPT(m.size()); |
59 | assert(m.size() == 2 * s); |
60 | } |
61 | } |
62 | |
63 | int main(int, char**) { |
64 | test<std::vector<int>, std::vector<char>>(); |
65 | test<std::deque<int>, std::vector<char>>(); |
66 | test<MinSequenceContainer<int>, MinSequenceContainer<char>>(); |
67 | test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>(); |
68 | |
69 | return 0; |
70 | } |
71 | |