2 // Testing utilities for the rvalue reference.
4 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
23 #ifndef _GLIBCXX_TESTSUITE_RVALREF_H
24 #define _GLIBCXX_TESTSUITE_RVALREF_H 1
26 #include <testsuite_hooks.h>
27 #include <bits/functional_hash.h>
31 // This class is designed to test libstdc++'s template-based rvalue
32 // reference support. It should fail at compile-time if there is an
33 // attempt to copy it.
39 rvalstruct() : val(0), valid(true)
42 rvalstruct(int inval
) : val(inval
), valid(true)
53 rvalstruct(const rvalstruct
&) = delete;
55 rvalstruct(rvalstruct
&& in
)
57 bool test
__attribute__((unused
)) = true;
58 VERIFY( in
.valid
== true );
65 operator=(const rvalstruct
&) = delete;
68 operator=(rvalstruct
&& in
)
70 bool test
__attribute__((unused
)) = true;
71 VERIFY( in
.valid
== true );
80 operator==(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
81 { return lhs
.val
== rhs
.val
; }
84 operator<(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
85 { return lhs
.val
< rhs
.val
; }
88 swap(rvalstruct
& lhs
, rvalstruct
& rhs
)
90 bool test
__attribute__((unused
)) = true;
91 VERIFY( lhs
.valid
&& rhs
.valid
);
97 // This is a moveable class which copies how many times it is copied.
98 // This is mainly of use in the containers, where the an element inserted
99 // into a container has to be copied once to get there, but we want to check
100 // nothing else is copied.
103 static int copycount
;
107 copycounter() : val(0), valid(true)
110 copycounter(int inval
) : val(inval
), valid(true)
113 copycounter(const copycounter
& in
) : val(in
.val
), valid(true)
115 bool test
__attribute__((unused
)) = true;
116 VERIFY( in
.valid
== true );
120 copycounter(copycounter
&& in
) noexcept
122 bool test
__attribute__((unused
)) = true;
123 VERIFY( in
.valid
== true );
130 operator=(int newval
)
138 operator=(const copycounter
& in
)
140 bool test
__attribute__((unused
)) = true;
141 VERIFY( in
.valid
== true );
149 operator=(copycounter
&& in
)
151 bool test
__attribute__((unused
)) = true;
152 VERIFY(in
.valid
== true);
159 ~copycounter() noexcept
163 int copycounter::copycount
= 0;
166 operator==(const copycounter
& lhs
, const copycounter
& rhs
)
167 { return lhs
.val
== rhs
.val
; }
170 operator<(const copycounter
& lhs
, const copycounter
& rhs
)
171 { return lhs
.val
< rhs
.val
; }
174 swap(copycounter
& lhs
, copycounter
& rhs
)
176 bool test
__attribute__((unused
)) = true;
177 VERIFY( lhs
.valid
&& rhs
.valid
);
183 // In the occasion of libstdc++/48038.
184 struct rvalstruct_compare_by_value
189 rvalstruct_compare_by_value(int v
)
190 : val(v
), ok(true) { }
192 rvalstruct_compare_by_value(const rvalstruct_compare_by_value
& rh
)
193 : val(rh
.val
), ok(rh
.ok
)
195 bool test
__attribute__((unused
)) = true;
199 rvalstruct_compare_by_value
&
200 operator=(const rvalstruct_compare_by_value
& rh
)
202 bool test
__attribute__((unused
)) = true;
209 rvalstruct_compare_by_value(rvalstruct_compare_by_value
&& rh
)
210 : val(rh
.val
), ok(rh
.ok
)
212 bool test
__attribute__((unused
)) = true;
217 rvalstruct_compare_by_value
&
218 operator=(rvalstruct_compare_by_value
&& rh
)
220 bool test
__attribute__((unused
)) = true;
230 operator<(rvalstruct_compare_by_value lh
,
231 rvalstruct_compare_by_value rh
)
233 bool test
__attribute__((unused
)) = true;
236 return lh
.val
< rh
.val
;
240 order(rvalstruct_compare_by_value lh
,
241 rvalstruct_compare_by_value rh
)
243 bool test
__attribute__((unused
)) = true;
246 return lh
.val
< rh
.val
;
249 struct throwing_move_constructor
251 throwing_move_constructor() = default;
253 throwing_move_constructor(throwing_move_constructor
&&)
256 throwing_move_constructor(const throwing_move_constructor
&) = default;
259 } // namespace __gnu_test
263 /// std::hash specialization for __gnu_test::rvalstruct.
265 struct hash
<__gnu_test::rvalstruct
>
267 typedef size_t result_type
;
268 typedef __gnu_test::rvalstruct argument_type
;
271 operator()(const __gnu_test::rvalstruct
& __rvs
) const
272 { return __rvs
.val
; }
276 #endif // _GLIBCXX_TESTSUITE_TR1_H