]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/map/operators/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / 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 // This test verifies that the value type of a map need not be default copyable.
19
20 // { dg-do run { target c++11 } }
21
22 #include <map>
23 #include <testsuite_hooks.h>
24 #include <testsuite_rvalref.h>
25 #include <testsuite_counter_type.h>
26
27 struct Mapped
28 {
29 Mapped() = default;
30 explicit Mapped(const Mapped&) = default;
31 };
32
33 struct DefaultConstructibleType
34 {
35 int val;
36
37 DefaultConstructibleType() : val(123)
38 {}
39
40 DefaultConstructibleType(const DefaultConstructibleType&) = delete;
41 DefaultConstructibleType(DefaultConstructibleType&&) = delete;
42
43 DefaultConstructibleType& operator=(int x)
44 {
45 val = x;
46 return *this;
47 }
48 };
49
50 void test01()
51 {
52 using __gnu_test::rvalstruct;
53 using __gnu_test::counter_type;
54
55 std::map<int, Mapped> m1;
56 m1[0] = Mapped();
57
58 std::map<int, rvalstruct> m2;
59 m2[0] = rvalstruct(13);
60
61 std::map<int, DefaultConstructibleType> m3;
62 VERIFY( m3[0].val == 123 );
63 VERIFY( m3.size() == 1 );
64 m3[0] = 2;
65 VERIFY( m3[0].val == 2 );
66
67 std::map<counter_type, int> m4;
68 VERIFY( m4[counter_type(1)] == 0 );
69 VERIFY( counter_type::specialize_count == 1 );
70 VERIFY( counter_type::copy_count == 0 );
71 VERIFY( counter_type::move_count == 1 );
72
73 counter_type k(2);
74 counter_type::reset();
75
76 VERIFY( m4[k] == 0 );
77 VERIFY( counter_type::copy_count == 1 );
78 VERIFY( counter_type::move_count == 0 );
79 }
80
81 int main()
82 {
83 test01();
84 return 0;
85 }