]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
e63637ea
BK
1// { dg-options "-Wno-deprecated" }
2
1985f1cd
MA
3// 2004-07-26 Matt Austern <austern@apple.com>
4//
a945c346 5// Copyright (C) 2003-2024 Free Software Foundation, Inc.
1985f1cd
MA
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
748086b7 10// Free Software Foundation; either version 3, or (at your option)
1985f1cd
MA
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
748086b7
JJ
19// with this library; see the file COPYING3. If not see
20// <http://www.gnu.org/licenses/>.
1985f1cd 21//
1985f1cd 22
e63637ea 23#include <hash_set>
1985f1cd
MA
24#include <functional>
25#include <iterator>
26#include <testsuite_allocator.h>
27
28using namespace __gnu_test;
29
30int main()
31{
32 typedef __gnu_cxx::hash_set<int, __gnu_cxx::hash<int>, std::equal_to<int>,
9f9900db 33 tracker_allocator<int> >
1985f1cd
MA
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
cbcc9fe8
JW
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;
9958c7eb 46
9f9900db 47 tracker_allocator_counter::reset();
1985f1cd
MA
48 {
49 Container c;
50 buckets = c.bucket_count();
cbcc9fe8 51 ok = check_construct_destroy("empty container", buckets+extra, extra) && ok;
1985f1cd 52 }
cbcc9fe8 53 ok = check_construct_destroy("empty container", buckets+extra, buckets+extra) && ok;
1985f1cd
MA
54
55
9f9900db 56 tracker_allocator_counter::reset();
1985f1cd
MA
57 {
58 Container c(arr10, arr10 + 10);
cbcc9fe8 59 ok = check_construct_destroy("Construct from range", buckets+10+extra, extra) && ok;
1985f1cd 60 }
cbcc9fe8 61 ok = check_construct_destroy("Construct from range", buckets+10+extra, buckets+10+extra) && ok;
1985f1cd 62
9f9900db 63 tracker_allocator_counter::reset();
1985f1cd
MA
64 {
65 Container c(arr10, arr10 + 10);
66 c.insert(arr10a[0]);
cbcc9fe8 67 ok = check_construct_destroy("Insert element", buckets+11+extra, extra) && ok;
1985f1cd 68 }
cbcc9fe8 69 ok = check_construct_destroy("Insert element", buckets+11+extra, buckets+11+extra) && ok;
1985f1cd 70
9f9900db 71 tracker_allocator_counter::reset();
1985f1cd
MA
72 {
73 Container c(arr10, arr10 + 10);
74 c.insert(arr10a, arr10a+3);
cbcc9fe8 75 ok = check_construct_destroy("Insert short range", buckets+13+extra, extra) && ok;
1985f1cd 76 }
cbcc9fe8 77 ok = check_construct_destroy("Insert short range", buckets+13+extra, buckets+13+extra) && ok;
1985f1cd 78
9f9900db 79 tracker_allocator_counter::reset();
1985f1cd
MA
80 {
81 Container c(arr10, arr10 + 10);
82 c.insert(arr10a, arr10a+10);
cbcc9fe8 83 ok = check_construct_destroy("Insert long range", buckets+20+extra, extra) && ok;
1985f1cd 84 }
cbcc9fe8 85 ok = check_construct_destroy("Insert long range", buckets+20+extra, buckets+20+extra) && ok;
1985f1cd
MA
86
87 return ok ? 0 : 1;
88}
89