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 count(const key_type& x) const;
14
15#include <cassert>
16#include <deque>
17#include <flat_set>
18#include <functional>
19#include <utility>
20
21#include "MinSequenceContainer.h"
22#include "test_macros.h"
23#include "min_allocator.h"
24
25template <class KeyContainer>
26void test_one() {
27 using Key = typename KeyContainer::value_type;
28 using S = typename KeyContainer::size_type;
29
30 {
31 using M = std::flat_multiset<Key, std::less<>, KeyContainer>;
32 M m = {1, 2, 2, 2, 2, 4, 4, 5, 8, 8, 8};
33 ASSERT_SAME_TYPE(decltype(m.count(0)), S);
34 assert(m.count(0) == 0);
35 assert(m.count(1) == 1);
36 assert(m.count(2) == 4);
37 assert(m.count(3) == 0);
38 assert(m.count(4) == 2);
39 assert(m.count(5) == 1);
40 assert(m.count(6) == 0);
41 assert(m.count(7) == 0);
42 assert(std::as_const(m).count(8) == 3);
43 assert(std::as_const(m).count(9) == 0);
44 }
45 {
46 using M = std::flat_multiset<Key, std::greater<int>, KeyContainer>;
47 M m = {1, 2, 4, 4, 4, 4, 5, 5, 8};
48 ASSERT_SAME_TYPE(decltype(m.count(0)), S);
49 assert(m.count(0) == 0);
50 assert(m.count(1) == 1);
51 assert(m.count(2) == 1);
52 assert(m.count(3) == 0);
53 assert(m.count(4) == 4);
54 assert(m.count(5) == 2);
55 assert(m.count(6) == 0);
56 assert(m.count(7) == 0);
57 assert(std::as_const(m).count(8) == 1);
58 assert(std::as_const(m).count(9) == 0);
59 }
60 {
61 // empty
62 using M = std::flat_multiset<Key, std::less<>, KeyContainer>;
63 M m;
64 assert(m.count(0) == 0);
65 assert(m.count(1) == 0);
66 }
67}
68
69void test() {
70 test_one<std::vector<int>>();
71 test_one<std::deque<int>>();
72 test_one<MinSequenceContainer<int>>();
73 test_one<std::vector<int, min_allocator<int>>>();
74}
75
76int main(int, char**) {
77 test();
78
79 return 0;
80}
81

source code of libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.operations/count.pass.cpp