]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_set/allocator/move_assign.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / allocator / move_assign.cc
CommitLineData
fbd26352 1// Copyright (C) 2013-2019 Free Software Foundation, Inc.
60eba405 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
be58e01d 18// { dg-do run { target c++11 } }
60eba405 19
20#include <unordered_set>
d8552953 21
60eba405 22#include <testsuite_hooks.h>
23#include <testsuite_allocator.h>
24#include <testsuite_counter_type.h>
25
26using __gnu_test::propagating_allocator;
27using __gnu_test::counter_type;
d8552953 28using __gnu_test::tracker_allocator;
29using __gnu_test::tracker_allocator_counter;
60eba405 30
31void test01()
32{
d8552953 33 tracker_allocator_counter::reset();
34 {
35 typedef propagating_allocator<counter_type, false,
36 tracker_allocator<counter_type>> alloc_type;
37 typedef __gnu_test::counter_type_hasher hash;
38 typedef std::unordered_set<counter_type, hash,
39 std::equal_to<counter_type>,
40 alloc_type> test_type;
41
42 test_type v1(alloc_type(1));
43 v1.emplace(0);
60eba405 44
d8552953 45 test_type v2(alloc_type(2));
46 v2.emplace(1);
60eba405 47
d8552953 48 counter_type::reset();
60eba405 49
d8552953 50 v2 = std::move(v1);
60eba405 51
d8552953 52 VERIFY( 1 == v1.get_allocator().get_personality() );
53 VERIFY( 2 == v2.get_allocator().get_personality() );
60eba405 54
d8552953 55 VERIFY( counter_type::move_count == 1 );
56 VERIFY( counter_type::destructor_count == 2 );
57 }
60eba405 58
d8552953 59 // Check there's nothing left allocated or constructed.
60 VERIFY( tracker_allocator_counter::get_construct_count()
61 == tracker_allocator_counter::get_destruct_count() );
62 VERIFY( tracker_allocator_counter::get_allocation_count()
63 == tracker_allocator_counter::get_deallocation_count() );
60eba405 64}
65
66void test02()
67{
d8552953 68 tracker_allocator_counter::reset();
69 {
70 typedef propagating_allocator<counter_type, true,
71 tracker_allocator<counter_type>> alloc_type;
72 typedef __gnu_test::counter_type_hasher hash;
73 typedef std::unordered_set<counter_type, hash,
74 std::equal_to<counter_type>,
75 alloc_type> test_type;
76
77 test_type v1(alloc_type(1));
78 v1.emplace(0);
60eba405 79
d8552953 80 auto it = v1.begin();
60eba405 81
d8552953 82 test_type v2(alloc_type(2));
83 v2.emplace(0);
b25436b0 84
d8552953 85 counter_type::reset();
60eba405 86
d8552953 87 v2 = std::move(v1);
60eba405 88
d8552953 89 VERIFY(0 == v1.get_allocator().get_personality());
90 VERIFY(1 == v2.get_allocator().get_personality());
60eba405 91
d8552953 92 VERIFY( counter_type::move_count == 0 );
93 VERIFY( counter_type::copy_count == 0 );
94 VERIFY( counter_type::destructor_count == 1 );
60eba405 95
d8552953 96 VERIFY( it == v2.begin() );
97 }
b25436b0 98
d8552953 99 // Check there's nothing left allocated or constructed.
100 VERIFY( tracker_allocator_counter::get_construct_count()
101 == tracker_allocator_counter::get_destruct_count() );
102 VERIFY( tracker_allocator_counter::get_allocation_count()
103 == tracker_allocator_counter::get_deallocation_count() );
104}
105
106void test03()
107{
108 tracker_allocator_counter::reset();
109 {
110 typedef propagating_allocator<counter_type, false,
111 tracker_allocator<counter_type>> alloc_type;
112 typedef __gnu_test::counter_type_hasher hash;
113 typedef std::unordered_set<counter_type, hash,
114 std::equal_to<counter_type>,
115 alloc_type> test_type;
116
117 test_type v1(alloc_type(1));
118 v1.emplace(0);
119
120 test_type v2(alloc_type(2));
121 int i = 0;
122 v2.emplace(i++);
123 for (; v2.bucket_count() == v1.bucket_count(); ++i)
124 v2.emplace(i);
125
126 counter_type::reset();
127
128 v2 = std::move(v1);
129
130 VERIFY( 1 == v1.get_allocator().get_personality() );
131 VERIFY( 2 == v2.get_allocator().get_personality() );
132
133 VERIFY( counter_type::move_count == 1 );
134 VERIFY( counter_type::destructor_count == i + 1 );
135 }
136
137 // Check there's nothing left allocated or constructed.
138 VERIFY( tracker_allocator_counter::get_construct_count()
139 == tracker_allocator_counter::get_destruct_count() );
140 VERIFY( tracker_allocator_counter::get_allocation_count()
141 == tracker_allocator_counter::get_deallocation_count() );
60eba405 142}
143
144int main()
145{
146 test01();
147 test02();
d8552953 148 test03();
60eba405 149 return 0;
150}