]>
Commit | Line | Data |
---|---|---|
181a5a13 FD |
1 | // -*- C++ -*- |
2 | // | |
99dee823 | 3 | // Copyright (C) 2012-2021 Free Software Foundation, Inc. |
181a5a13 FD |
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; | |
734f5023 | 35 | #if __cplusplus >= 201103L |
181a5a13 FD |
36 | static int move_count; |
37 | static int move_assign_count; | |
38 | #endif | |
0462b6aa | 39 | static int destructor_count; |
181a5a13 FD |
40 | |
41 | int val; | |
f92ab29f | 42 | |
181a5a13 | 43 | counter_type() : val(0) |
0462b6aa | 44 | { ++default_count; } |
181a5a13 FD |
45 | |
46 | counter_type(int inval) : val(inval) | |
0462b6aa | 47 | { ++specialize_count; } |
181a5a13 FD |
48 | |
49 | counter_type(const counter_type& in) : val(in.val) | |
0462b6aa FD |
50 | { ++copy_count; } |
51 | ||
52 | ~counter_type() | |
53 | { ++destructor_count; } | |
181a5a13 FD |
54 | |
55 | counter_type& | |
56 | operator=(const counter_type& in) | |
57 | { | |
58 | val = in.val; | |
59 | ++copy_assign_count; | |
60 | return *this; | |
61 | } | |
62 | ||
734f5023 | 63 | #if __cplusplus >= 201103L |
181a5a13 FD |
64 | counter_type(counter_type&& in) noexcept |
65 | { | |
66 | val = in.val; | |
67 | ++move_count; | |
68 | } | |
69 | ||
70 | counter_type& | |
0462b6aa | 71 | operator=(counter_type&& rhs) noexcept |
181a5a13 FD |
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; | |
734f5023 | 87 | #if __cplusplus >= 201103L |
181a5a13 FD |
88 | move_count = 0; |
89 | move_assign_count = 0; | |
90 | #endif | |
0462b6aa | 91 | destructor_count = 0; |
181a5a13 FD |
92 | } |
93 | ||
94 | bool operator==(const counter_type& rhs) const | |
95 | { return val == rhs.val; } | |
96 | ||
97 | bool operator<(const counter_type& rhs) const | |
43ee3d5f FD |
98 | { |
99 | ++less_compare_count; | |
100 | return val < rhs.val; | |
101 | } | |
181a5a13 FD |
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 | ||
734f5023 | 110 | #if __cplusplus >= 201103L |
181a5a13 FD |
111 | int counter_type::move_count = 0; |
112 | int counter_type::move_assign_count = 0; | |
113 | #endif | |
0462b6aa | 114 | int counter_type::destructor_count = 0; |
181a5a13 FD |
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 |