1 // Copyright (C) 2013-2023 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++11 } }
20 #include <unordered_set>
22 #include <testsuite_hooks.h>
23 #include <testsuite_allocator.h>
24 #include <testsuite_counter_type.h>
26 using __gnu_test::propagating_allocator
;
27 using __gnu_test::counter_type
;
28 using __gnu_test::tracker_allocator
;
29 using __gnu_test::tracker_allocator_counter
;
33 tracker_allocator_counter::reset();
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
;
42 test_type
v1(alloc_type(1));
45 test_type
v2(alloc_type(2));
48 counter_type::reset();
52 VERIFY( 1 == v1
.get_allocator().get_personality() );
53 VERIFY( 2 == v2
.get_allocator().get_personality() );
55 VERIFY( counter_type::move_count
== 1 );
56 VERIFY( counter_type::destructor_count
== 2 );
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() );
68 tracker_allocator_counter::reset();
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
;
77 test_type
v1(alloc_type(1));
82 test_type
v2(alloc_type(2));
85 counter_type::reset();
89 VERIFY(1 == v1
.get_allocator().get_personality());
90 VERIFY(1 == v2
.get_allocator().get_personality());
92 VERIFY( counter_type::move_count
== 0 );
93 VERIFY( counter_type::copy_count
== 0 );
94 VERIFY( counter_type::destructor_count
== 1 );
96 VERIFY( it
== v2
.begin() );
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() );
108 tracker_allocator_counter::reset();
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
;
117 test_type
v1(alloc_type(1));
120 test_type
v2(alloc_type(2));
123 for (; v2
.bucket_count() == v1
.bucket_count(); ++i
)
126 counter_type::reset();
130 VERIFY( 1 == v1
.get_allocator().get_personality() );
131 VERIFY( 2 == v2
.get_allocator().get_personality() );
133 VERIFY( counter_type::move_count
== 1 );
134 VERIFY( counter_type::destructor_count
== i
+ 1 );
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() );