| 1 |
// -*- C++ -*- |
| 2 |
// |
| 3 |
// Copyright (C) 2012-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
// |
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
// |
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
// |
| 20 |
|
| 21 |
#ifndef _TESTSUITE_COUNTER_TYPE_H |
| 22 |
#define _TESTSUITE_COUNTER_TYPE_H 1 |
| 23 |
|
| 24 |
namespace __gnu_test |
| 25 |
{ |
| 26 |
// Type counting how many constructors or assign operators are invoked. |
| 27 |
struct counter_type |
| 28 |
{ |
| 29 |
// Constructor counters: |
| 30 |
static int default_count; |
| 31 |
static int specialize_count; |
| 32 |
static int copy_count; |
| 33 |
static int copy_assign_count; |
| 34 |
static int less_compare_count; |
| 35 |
#if __cplusplus >= 201103L |
| 36 |
static int move_count; |
| 37 |
static int move_assign_count; |
| 38 |
#endif |
| 39 |
static int destructor_count; |
| 40 |
|
| 41 |
int val; |
| 42 |
|
| 43 |
counter_type() : val(0) |
| 44 |
{ ++default_count; } |
| 45 |
|
| 46 |
counter_type(int inval) : val(inval) |
| 47 |
{ ++specialize_count; } |
| 48 |
|
| 49 |
counter_type(const counter_type& in) : val(in.val) |
| 50 |
{ ++copy_count; } |
| 51 |
|
| 52 |
~counter_type() |
| 53 |
{ ++destructor_count; } |
| 54 |
|
| 55 |
counter_type& |
| 56 |
operator=(const counter_type& in) |
| 57 |
{ |
| 58 |
val = in.val; |
| 59 |
++copy_assign_count; |
| 60 |
return *this; |
| 61 |
} |
| 62 |
|
| 63 |
#if __cplusplus >= 201103L |
| 64 |
counter_type(counter_type&& in) noexcept |
| 65 |
{ |
| 66 |
val = in.val; |
| 67 |
++move_count; |
| 68 |
} |
| 69 |
|
| 70 |
counter_type& |
| 71 |
operator=(counter_type&& rhs) noexcept |
| 72 |
{ |
| 73 |
val = rhs.val; |
| 74 |
++move_assign_count; |
| 75 |
return *this; |
| 76 |
} |
| 77 |
#endif |
| 78 |
|
| 79 |
static void |
| 80 |
reset() |
| 81 |
{ |
| 82 |
default_count = 0; |
| 83 |
specialize_count = 0; |
| 84 |
copy_count = 0; |
| 85 |
copy_assign_count = 0; |
| 86 |
less_compare_count = 0; |
| 87 |
#if __cplusplus >= 201103L |
| 88 |
move_count = 0; |
| 89 |
move_assign_count = 0; |
| 90 |
#endif |
| 91 |
destructor_count = 0; |
| 92 |
} |
| 93 |
|
| 94 |
bool operator==(const counter_type& rhs) const |
| 95 |
{ return val == rhs.val; } |
| 96 |
|
| 97 |
bool operator<(const counter_type& rhs) const |
| 98 |
{ |
| 99 |
++less_compare_count; |
| 100 |
return val < rhs.val; |
| 101 |
} |
| 102 |
}; |
| 103 |
|
| 104 |
int counter_type::default_count = 0; |
| 105 |
int counter_type::specialize_count = 0; |
| 106 |
int counter_type::copy_count = 0; |
| 107 |
int counter_type::copy_assign_count = 0; |
| 108 |
int counter_type::less_compare_count = 0; |
| 109 |
|
| 110 |
#if __cplusplus >= 201103L |
| 111 |
int counter_type::move_count = 0; |
| 112 |
int counter_type::move_assign_count = 0; |
| 113 |
#endif |
| 114 |
int counter_type::destructor_count = 0; |
| 115 |
|
| 116 |
struct counter_type_hasher |
| 117 |
{ |
| 118 |
std::size_t operator()(const counter_type& c) const |
| 119 |
{ |
| 120 |
return c.val; |
| 121 |
} |
| 122 |
}; |
| 123 |
|
| 124 |
} // namespace __gnu_test |
| 125 |
#endif |