1 // -*- C++ -*- 2 // 3 // Copyright (C) 2012-2013 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 40 int val; 41 counter_typecounter_type42 counter_type() : val(0) 43 { 44 ++default_count; 45 } 46 counter_typecounter_type47 counter_type(int inval) : val(inval) 48 { 49 ++specialize_count; 50 } 51 counter_typecounter_type52 counter_type(const counter_type& in) : val(in.val) 53 { 54 ++copy_count; 55 } 56 57 counter_type& 58 operator=(const counter_type& in) 59 { 60 val = in.val; 61 ++copy_assign_count; 62 return *this; 63 } 64 65 #if __cplusplus >= 201103L counter_typecounter_type66 counter_type(counter_type&& in) noexcept 67 { 68 val = in.val; 69 ++move_count; 70 } 71 72 counter_type& 73 operator=(counter_type&& rhs) 74 { 75 val = rhs.val; 76 ++move_assign_count; 77 return *this; 78 } 79 #endif 80 81 static void resetcounter_type82 reset() 83 { 84 default_count = 0; 85 specialize_count = 0; 86 copy_count = 0; 87 copy_assign_count = 0; 88 less_compare_count = 0; 89 #if __cplusplus >= 201103L 90 move_count = 0; 91 move_assign_count = 0; 92 #endif 93 } 94 95 bool operator==(const counter_type& rhs) const 96 { return val == rhs.val; } 97 98 bool operator<(const counter_type& rhs) const 99 { return val < rhs.val; } 100 }; 101 102 int counter_type::default_count = 0; 103 int counter_type::specialize_count = 0; 104 int counter_type::copy_count = 0; 105 int counter_type::copy_assign_count = 0; 106 int counter_type::less_compare_count = 0; 107 108 #if __cplusplus >= 201103L 109 int counter_type::move_count = 0; 110 int counter_type::move_assign_count = 0; 111 #endif 112 113 struct counter_type_hasher 114 { operatorcounter_type_hasher115 std::size_t operator()(const counter_type& c) const 116 { 117 return c.val; 118 } 119 }; 120 121 } // namespace __gnu_test 122 #endif 123