1 // { dg-do run { target c++11 } }
3 // 2011-10-28 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2011-2025 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
23 #include <unordered_map>
24 #include <testsuite_hooks.h>
30 typedef unordered_map
<int, int>::value_type value_type
;
32 unordered_map
<int, int> um0
;
33 VERIFY( um0
.count(0) == 0 );
34 VERIFY( um0
.count(1) == 0 );
36 um0
.insert(value_type(1, 1));
37 VERIFY( um0
.count(0) == 0 );
38 VERIFY( um0
.count(1) == 1 );
40 um0
.insert(value_type(1, 2));
41 VERIFY( um0
.count(0) == 0 );
42 VERIFY( um0
.count(1) == 1 );
44 um0
.insert(value_type(2, 1));
45 VERIFY( um0
.count(2) == 1 );
47 um0
.insert(value_type(3, 1));
48 um0
.insert(value_type(3, 2));
49 um0
.insert(value_type(3, 3));
50 VERIFY( um0
.count(3) == 1 );
53 VERIFY( um0
.count(2) == 0 );
56 VERIFY( um0
.count(0) == 0 );
58 unordered_map
<int, int> um1(um0
);
59 VERIFY( um1
.count(0) == 0 );
60 VERIFY( um1
.count(1) == 1 );
61 VERIFY( um1
.count(2) == 0 );
62 VERIFY( um1
.count(3) == 1 );
65 VERIFY( um0
.count(0) == 0 );
66 VERIFY( um0
.count(1) == 0 );
67 VERIFY( um0
.count(2) == 0 );
68 VERIFY( um0
.count(3) == 0 );
70 um1
.insert(value_type(4, 1));
71 um1
.insert(value_type(5, 1));
72 um1
.insert(value_type(5, 2));
73 um1
.insert(value_type(5, 3));
74 um1
.insert(value_type(5, 4));
75 VERIFY( um1
.count(4) == 1 );
76 VERIFY( um1
.count(5) == 1 );
79 VERIFY( um1
.count(1) == 0 );
81 um1
.erase(um1
.find(5));
82 VERIFY( um1
.count(5) == 0 );
84 um1
.insert(value_type(1, 1));
85 um1
.insert(value_type(1, 2));
86 VERIFY( um1
.count(1) == 1 );
89 VERIFY( um1
.count(5) == 0 );
91 um1
.erase(um1
.find(4));
92 VERIFY( um1
.count(4) == 0 );
95 VERIFY( um1
.count(0) == 0 );
96 VERIFY( um1
.count(1) == 0 );
97 VERIFY( um1
.count(2) == 0 );
98 VERIFY( um1
.count(3) == 0 );
99 VERIFY( um1
.count(4) == 0 );
100 VERIFY( um1
.count(5) == 0 );