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_set>
12
13// size_type size() const noexcept;
14
15#include <cassert>
16#include <deque>
17#include <flat_set>
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>
26void test_one() {
27 using M = std::flat_multiset<int, std::less<int>, KeyContainer>;
28 using S = typename M::size_type;
29 {
30 const M m = {1, 1, 4, 5, 5};
31 ASSERT_SAME_TYPE(decltype(m.size()), S);
32 ASSERT_NOEXCEPT(m.size());
33 assert(m.size() == 5);
34 }
35 {
36 const M m = {1};
37 ASSERT_SAME_TYPE(decltype(m.size()), S);
38 ASSERT_NOEXCEPT(m.size());
39 assert(m.size() == 1);
40 }
41 {
42 const M m;
43 ASSERT_SAME_TYPE(decltype(m.size()), S);
44 ASSERT_NOEXCEPT(m.size());
45 assert(m.size() == 0);
46 }
47 {
48 M m;
49 S s = 500000;
50 for (std::size_t i = 0u; i < s; ++i) {
51 m.emplace(i);
52 m.emplace(i);
53 }
54 ASSERT_SAME_TYPE(decltype(m.size()), S);
55 ASSERT_NOEXCEPT(m.size());
56 assert(m.size() == 2 * s);
57 }
58}
59
60void test() {
61 test_one<std::vector<int>>();
62 test_one<std::deque<int>>();
63 test_one<MinSequenceContainer<int>>();
64 test_one<std::vector<int, min_allocator<int>>>();
65}
66
67int main(int, char**) {
68 test();
69
70 return 0;
71}
72

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