2014-03-04 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / util / testsuite_counter_type.h
blob43a9ea3c37b991947a63a9c106d5dba2995d4d46
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2012-2014 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.
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.
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/>.
21 #ifndef _TESTSUITE_COUNTER_TYPE_H
22 #define _TESTSUITE_COUNTER_TYPE_H 1
24 namespace __gnu_test
26 // Type counting how many constructors or assign operators are invoked.
27 struct counter_type
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;
41 int val;
43 counter_type() : val(0)
44 { ++default_count; }
46 counter_type(int inval) : val(inval)
47 { ++specialize_count; }
49 counter_type(const counter_type& in) : val(in.val)
50 { ++copy_count; }
52 ~counter_type()
53 { ++destructor_count; }
55 counter_type&
56 operator=(const counter_type& in)
58 val = in.val;
59 ++copy_assign_count;
60 return *this;
63 #if __cplusplus >= 201103L
64 counter_type(counter_type&& in) noexcept
66 val = in.val;
67 ++move_count;
70 counter_type&
71 operator=(counter_type&& rhs) noexcept
73 val = rhs.val;
74 ++move_assign_count;
75 return *this;
77 #endif
79 static void
80 reset()
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;
94 bool operator==(const counter_type& rhs) const
95 { return val == rhs.val; }
97 bool operator<(const counter_type& rhs) const
98 { return val < rhs.val; }
101 int counter_type::default_count = 0;
102 int counter_type::specialize_count = 0;
103 int counter_type::copy_count = 0;
104 int counter_type::copy_assign_count = 0;
105 int counter_type::less_compare_count = 0;
107 #if __cplusplus >= 201103L
108 int counter_type::move_count = 0;
109 int counter_type::move_assign_count = 0;
110 #endif
111 int counter_type::destructor_count = 0;
113 struct counter_type_hasher
115 std::size_t operator()(const counter_type& c) const
117 return c.val;
121 } // namespace __gnu_test
122 #endif