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_set<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() == 3);
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 = 1000000;
50 for (auto i = 0u; i < s; ++i) {
51 m.emplace(i);
52 }
53 ASSERT_SAME_TYPE(decltype(m.size()), S);
54 ASSERT_NOEXCEPT(m.size());
55 assert(m.size() == s);
56 }
57}
58
59void test() {
60 test_one<std::vector<int>>();
61 test_one<std::deque<int>>();
62 test_one<MinSequenceContainer<int>>();
63 test_one<std::vector<int, min_allocator<int>>>();
64}
65
66int main(int, char**) {
67 test();
68
69 return 0;
70}
71

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