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

source code of libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/size.pass.cpp