2 // Testing utilities for the rvalue reference.
4 // Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
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)
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>
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).
36 operator=(const rvalstruct
&);
38 rvalstruct(const rvalstruct
&);
44 rvalstruct() : valid(false)
47 rvalstruct(int inval
) : val(inval
), valid(true)
53 VERIFY(valid
== false);
59 rvalstruct(rvalstruct
&& in
)
61 VERIFY(in
.valid
== true);
68 operator=(rvalstruct
&& in
)
70 VERIFY(in
.valid
== true);
79 operator==(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
80 { return lhs
.val
== rhs
.val
; }
83 operator<(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
84 { return lhs
.val
< rhs
.val
; }
87 swap(rvalstruct
& lhs
, rvalstruct
& rhs
)
89 VERIFY(lhs
.valid
&& rhs
.valid
);
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.
101 static int copycount
;
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);
117 copycounter(copycounter
&& in
)
119 VERIFY(in
.valid
== true);
126 operator=(int newval
)
134 operator=(const copycounter
& in
)
136 VERIFY(in
.valid
== true);
144 operator=(copycounter
&& in
)
146 VERIFY(in
.valid
== true);
157 int copycounter::copycount
= 0;
160 operator==(const copycounter
& lhs
, const copycounter
& rhs
)
161 { return lhs
.val
== rhs
.val
; }
164 operator<(const copycounter
& lhs
, const copycounter
& rhs
)
165 { return lhs
.val
< rhs
.val
; }
168 swap(copycounter
& lhs
, copycounter
& rhs
)
170 VERIFY(lhs
.valid
&& rhs
.valid
);
176 } // namespace __gnu_test
178 #endif // _GLIBCXX_TESTSUITE_TR1_H