]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_map/operators/2.cc
f5547fad462b5d960a29d9b7e17b3727bdfbd760
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_map / operators / 2.cc
1 // Copyright (C) 2012-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 23.5.4 template class unordered_map
19
20 // This test verifies that the value type of a unordered_map need not be
21 // default copyable.
22
23 // { dg-do run { target c++11 } }
24
25 #include <unordered_map>
26 #include <testsuite_hooks.h>
27 #include <testsuite_rvalref.h>
28 #include <testsuite_counter_type.h>
29
30 struct Mapped
31 {
32 Mapped() = default;
33 explicit Mapped(const Mapped&) = default;
34 };
35
36 struct DefaultConstructibleType
37 {
38 int val;
39
40 DefaultConstructibleType() : val(123)
41 {}
42
43 DefaultConstructibleType(const DefaultConstructibleType&) = delete;
44 DefaultConstructibleType(DefaultConstructibleType&&) = delete;
45
46 DefaultConstructibleType& operator=(int x)
47 {
48 val = x;
49 return *this;
50 }
51 };
52
53 void test01()
54 {
55 using __gnu_test::rvalstruct;
56 using __gnu_test::counter_type;
57
58 std::unordered_map<int, Mapped> m1;
59 m1[0] = Mapped();
60
61 std::unordered_map<int, rvalstruct> m2;
62 m2[0] = rvalstruct(13);
63
64 std::unordered_map<int, DefaultConstructibleType> m3;
65 VERIFY( m3[0].val == 123 );
66 VERIFY( m3.size() == 1 );
67 m3[0] = 2;
68 VERIFY( m3[0].val == 2 );
69
70 std::unordered_map<counter_type, int,
71 __gnu_test::counter_type_hasher> m4;
72 VERIFY( m4[counter_type(1)] == 0 );
73 VERIFY( counter_type::specialize_count == 1 );
74 VERIFY( counter_type::copy_count == 0 );
75 VERIFY( counter_type::move_count == 1 );
76
77 counter_type k(2);
78 counter_type::reset();
79
80 VERIFY( m4[k] == 0 );
81 VERIFY( counter_type::copy_count == 1 );
82 VERIFY( counter_type::move_count == 0 );
83 }
84
85 int main()
86 {
87 test01();
88 return 0;
89 }