Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / associative / map / map.ops / count.pass.cpp
blob9fa53ca05026c4a314288d5c81e7e84377ac09fb
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 //===----------------------------------------------------------------------===//
9 // <map>
11 // class map
13 // size_type count(const key_type& k) const;
15 #include <map>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "private_constructor.h"
21 #include "is_transparent.h"
23 #if TEST_STD_VER >= 11
24 template <class T>
25 struct FinalCompare final {
26 bool operator()(const T& x, const T& y) const { return x < y; }
28 #endif
30 template <class Map, class ArgType = typename Map::key_type>
31 void test() {
32 typedef typename Map::value_type V;
33 typedef typename Map::size_type R;
35 V ar[] = {V(5, 5), V(6, 6), V(7, 7), V(8, 8), V(9, 9), V(10, 10), V(11, 11), V(12, 12)};
37 const Map m(ar, ar + sizeof(ar) / sizeof(ar[0]));
39 for (int i = 0; i < 5; ++i) {
40 R r = m.count(ArgType(i));
41 assert(r == 0);
44 for (int i = 5; i < 13; ++i) {
45 R r = m.count(ArgType(i));
46 assert(r == 1);
50 int main(int, char**) {
51 test<std::map<int, double> >();
52 #if TEST_STD_VER >= 11
53 typedef std::pair<const int, double> V;
54 test<std::map<int, double, std::less<int>, min_allocator<V>>>();
55 test<std::map<int, double, FinalCompare<int>>>();
56 #endif
57 #if TEST_STD_VER >= 14
58 typedef std::map<int, double, std::less<>> TM;
59 test<TM>();
60 test<TM, C2Int>();
63 typedef PrivateConstructor PC;
64 typedef std::map<PC, double, std::less<> > M;
65 typedef M::size_type R;
67 M m;
68 m[PC::make(5)] = 5;
69 m[PC::make(6)] = 6;
70 m[PC::make(7)] = 7;
71 m[PC::make(8)] = 8;
72 m[PC::make(9)] = 9;
73 m[PC::make(10)] = 10;
74 m[PC::make(11)] = 11;
75 m[PC::make(12)] = 12;
77 for (int i = 0; i < 5; ++i) {
78 R r = m.count(i);
79 assert(r == 0);
82 for (int i = 5; i < 13; ++i) {
83 R r = m.count(i);
84 assert(r == 1);
87 #endif // TEST_STD_VER >= 14
88 return 0;