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 count(const key_type& x) const;
14
15#include <cassert>
16#include <deque>
17#include <flat_map>
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, class ValueContainer>
26void test() {
27 using Key = typename KeyContainer::value_type;
28 using Value = typename ValueContainer::value_type;
29
30 {
31 using M = std::flat_map<Key, Value, std::less<>, KeyContainer, ValueContainer>;
32 M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}, {8, 8}};
33 ASSERT_SAME_TYPE(decltype(m.count(0)), size_t);
34 assert(m.count(0) == 0);
35 assert(m.count(1) == 1);
36 assert(m.count(2) == 1);
37 assert(m.count(3) == 0);
38 assert(m.count(4) == 1);
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) == 1);
43 assert(std::as_const(m).count(9) == 0);
44 }
45 {
46 using M = std::flat_map<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
47 M m = {{1, 0}, {2, 0}, {4, 0}, {5, 0}, {8, 0}};
48 ASSERT_SAME_TYPE(decltype(m.count(0)), size_t);
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) == 1);
54 assert(m.count(5) == 1);
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
62int main(int, char**) {
63 test<std::vector<int>, std::vector<int>>();
64 test<std::deque<int>, std::vector<int>>();
65 test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
66 test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
67
68 return 0;
69}
70

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