Fix change log
[official-gcc.git] / libstdc++-v3 / testsuite / util / testsuite_rvalref.h
blobb44d6ddd12d5071fae46af8672d9bd81c99bb37c
1 // -*- C++ -*-
2 // Testing utilities for the rvalue reference.
3 //
4 // Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #ifndef _GLIBCXX_TESTSUITE_RVALREF_H
23 #define _GLIBCXX_TESTSUITE_RVALREF_H 1
25 #include <testsuite_hooks.h>
27 namespace __gnu_test
30 // This class is designed to test libstdc++'s template-based rvalue
31 // reference support. It should fail at compile-time if there is an attempt
32 // to copy it (although see note just below).
33 class rvalstruct
35 bool
36 operator=(const rvalstruct&);
38 rvalstruct(const rvalstruct&);
40 public:
41 int val;
42 bool valid;
44 rvalstruct() : valid(false)
45 { }
47 rvalstruct(int inval) : val(inval), valid(true)
48 { }
50 rvalstruct&
51 operator=(int newval)
53 VERIFY(valid == false);
54 val = newval;
55 valid = true;
56 return *this;
59 rvalstruct(rvalstruct&& in)
61 VERIFY(in.valid == true);
62 val = in.val;
63 in.valid = false;
64 valid = true;
67 rvalstruct&
68 operator=(rvalstruct&& in)
70 VERIFY(in.valid == true);
71 val = in.val;
72 in.valid = false;
73 valid = true;
74 return *this;
78 bool
79 operator==(const rvalstruct& lhs, const rvalstruct& rhs)
80 { return lhs.val == rhs.val; }
82 bool
83 operator<(const rvalstruct& lhs, const rvalstruct& rhs)
84 { return lhs.val < rhs.val; }
86 void
87 swap(rvalstruct& lhs, rvalstruct& rhs)
89 VERIFY(lhs.valid && rhs.valid);
90 int temp = lhs.val;
91 lhs.val = rhs.val;
92 rhs.val = temp;
95 // This is a moveable class which copies how many times it is copied.
96 // This is mainly of use in the containers, where the an element inserted
97 // into a container has to be copied once to get there, but we want to check
98 // nothing else is copied.
99 struct copycounter
101 static int copycount;
102 int val;
103 bool valid;
105 copycounter() : val(0), valid(true)
108 copycounter(int inval) : val(inval), valid(true)
111 copycounter(const copycounter& in) : val(in.val), valid(true)
113 VERIFY(in.valid == true);
114 ++copycount;
117 copycounter(copycounter&& in)
119 VERIFY(in.valid == true);
120 val = in.val;
121 in.valid = false;
122 valid = true;
125 copycounter&
126 operator=(int newval)
128 val = newval;
129 valid = true;
130 return *this;
133 bool
134 operator=(const copycounter& in)
136 VERIFY(in.valid == true);
137 ++copycount;
138 val = in.val;
139 valid = true;
140 return true;
143 copycounter&
144 operator=(copycounter&& in)
146 VERIFY(in.valid == true);
147 val = in.val;
148 in.valid = false;
149 valid = true;
150 return *this;
153 ~copycounter()
154 { valid = false; }
157 int copycounter::copycount = 0;
159 bool
160 operator==(const copycounter& lhs, const copycounter& rhs)
161 { return lhs.val == rhs.val; }
163 bool
164 operator<(const copycounter& lhs, const copycounter& rhs)
165 { return lhs.val < rhs.val; }
167 void
168 swap(copycounter& lhs, copycounter& rhs)
170 VERIFY(lhs.valid && rhs.valid);
171 int temp = lhs.val;
172 lhs.val = rhs.val;
173 rhs.val = temp;
176 } // namespace __gnu_test
178 #endif // _GLIBCXX_TESTSUITE_TR1_H