]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/backward/hash_set/check_construct_destroy.cc
1 // { dg-options "-Wno-deprecated" }
3 // 2004-07-26 Matt Austern <austern@apple.com>
5 // Copyright (C) 2003-2020 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/>.
26 #include <testsuite_allocator.h>
28 using namespace __gnu_test
;
32 typedef __gnu_cxx::hash_set
<int, __gnu_cxx::hash
<int>, std::equal_to
<int>,
33 tracker_allocator
<int> >
36 const int arr10
[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
37 const int arr10a
[10] = { 31, 23, 82, 46, 13, 17, 30, 71, 22, 51 };
42 // For C++11 and later add 1 to all counts, because the std::vector used
43 // internally by the hashtable creates and destroys a temporary object
44 // using its allocator.
45 const int extra
= __cplusplus
>= 201102L ? 1 : 0;
47 tracker_allocator_counter::reset();
50 buckets
= c
.bucket_count();
51 ok
= check_construct_destroy("empty container", buckets
+extra
, extra
) && ok
;
53 ok
= check_construct_destroy("empty container", buckets
+extra
, buckets
+extra
) && ok
;
56 tracker_allocator_counter::reset();
58 Container
c(arr10
, arr10
+ 10);
59 ok
= check_construct_destroy("Construct from range", buckets
+10+extra
, extra
) && ok
;
61 ok
= check_construct_destroy("Construct from range", buckets
+10+extra
, buckets
+10+extra
) && ok
;
63 tracker_allocator_counter::reset();
65 Container
c(arr10
, arr10
+ 10);
67 ok
= check_construct_destroy("Insert element", buckets
+11+extra
, extra
) && ok
;
69 ok
= check_construct_destroy("Insert element", buckets
+11+extra
, buckets
+11+extra
) && ok
;
71 tracker_allocator_counter::reset();
73 Container
c(arr10
, arr10
+ 10);
74 c
.insert(arr10a
, arr10a
+3);
75 ok
= check_construct_destroy("Insert short range", buckets
+13+extra
, extra
) && ok
;
77 ok
= check_construct_destroy("Insert short range", buckets
+13+extra
, buckets
+13+extra
) && ok
;
79 tracker_allocator_counter::reset();
81 Container
c(arr10
, arr10
+ 10);
82 c
.insert(arr10a
, arr10a
+10);
83 ok
= check_construct_destroy("Insert long range", buckets
+20+extra
, extra
) && ok
;
85 ok
= check_construct_destroy("Insert long range", buckets
+20+extra
, buckets
+20+extra
) && ok
;