]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/backward/hash_set/check_construct_destroy.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / backward / hash_set / check_construct_destroy.cc
1 // { dg-options "-Wno-deprecated" }
2
3 // 2004-07-26 Matt Austern <austern@apple.com>
4 //
5 // Copyright (C) 2003-2020 Free Software Foundation, Inc.
6 //
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)
11 // any later version.
12 //
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.
17 //
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/>.
21 //
22
23 #include <hash_set>
24 #include <functional>
25 #include <iterator>
26 #include <testsuite_allocator.h>
27
28 using namespace __gnu_test;
29
30 int main()
31 {
32 typedef __gnu_cxx::hash_set<int, __gnu_cxx::hash<int>, std::equal_to<int>,
33 tracker_allocator<int> >
34 Container;
35
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 };
38 bool ok = true;
39
40 int buckets;
41
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;
46
47 tracker_allocator_counter::reset();
48 {
49 Container c;
50 buckets = c.bucket_count();
51 ok = check_construct_destroy("empty container", buckets+extra, extra) && ok;
52 }
53 ok = check_construct_destroy("empty container", buckets+extra, buckets+extra) && ok;
54
55
56 tracker_allocator_counter::reset();
57 {
58 Container c(arr10, arr10 + 10);
59 ok = check_construct_destroy("Construct from range", buckets+10+extra, extra) && ok;
60 }
61 ok = check_construct_destroy("Construct from range", buckets+10+extra, buckets+10+extra) && ok;
62
63 tracker_allocator_counter::reset();
64 {
65 Container c(arr10, arr10 + 10);
66 c.insert(arr10a[0]);
67 ok = check_construct_destroy("Insert element", buckets+11+extra, extra) && ok;
68 }
69 ok = check_construct_destroy("Insert element", buckets+11+extra, buckets+11+extra) && ok;
70
71 tracker_allocator_counter::reset();
72 {
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;
76 }
77 ok = check_construct_destroy("Insert short range", buckets+13+extra, buckets+13+extra) && ok;
78
79 tracker_allocator_counter::reset();
80 {
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;
84 }
85 ok = check_construct_destroy("Insert long range", buckets+20+extra, buckets+20+extra) && ok;
86
87 return ok ? 0 : 1;
88 }
89