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( this != &in
);
72 VERIFY( in
.valid
== true );
81 operator==(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
82 { return lhs
.val
== rhs
.val
; }
85 operator<(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
86 { return lhs
.val
< rhs
.val
; }
89 swap(rvalstruct
& lhs
, rvalstruct
& rhs
)
91 bool test
__attribute__((unused
)) = true;
92 VERIFY( lhs
.valid
&& rhs
.valid
);
98 // This is a moveable class which copies how many times it is copied.
99 // This is mainly of use in the containers, where the an element inserted
100 // into a container has to be copied once to get there, but we want to check
101 // nothing else is copied.
104 static int copycount
;
108 copycounter() : val(0), valid(true)
111 copycounter(int inval
) : val(inval
), valid(true)
114 copycounter(const copycounter
& in
) : val(in
.val
), valid(true)
116 bool test
__attribute__((unused
)) = true;
117 VERIFY( in
.valid
== true );
121 copycounter(copycounter
&& in
) noexcept
123 bool test
__attribute__((unused
)) = true;
124 VERIFY( in
.valid
== true );
131 operator=(int newval
)
139 operator=(const copycounter
& in
)
141 bool test
__attribute__((unused
)) = true;
142 VERIFY( in
.valid
== true );
150 operator=(copycounter
&& in
)
152 bool test
__attribute__((unused
)) = true;
153 VERIFY(in
.valid
== true);
160 ~copycounter() noexcept
164 int copycounter::copycount
= 0;
167 operator==(const copycounter
& lhs
, const copycounter
& rhs
)
168 { return lhs
.val
== rhs
.val
; }
171 operator<(const copycounter
& lhs
, const copycounter
& rhs
)
172 { return lhs
.val
< rhs
.val
; }
175 swap(copycounter
& lhs
, copycounter
& rhs
)
177 bool test
__attribute__((unused
)) = true;
178 VERIFY( lhs
.valid
&& rhs
.valid
);
184 // In the occasion of libstdc++/48038.
185 struct rvalstruct_compare_by_value
190 rvalstruct_compare_by_value(int v
)
191 : val(v
), ok(true) { }
193 rvalstruct_compare_by_value(const rvalstruct_compare_by_value
& rh
)
194 : val(rh
.val
), ok(rh
.ok
)
196 bool test
__attribute__((unused
)) = true;
200 rvalstruct_compare_by_value
&
201 operator=(const rvalstruct_compare_by_value
& rh
)
203 bool test
__attribute__((unused
)) = true;
210 rvalstruct_compare_by_value(rvalstruct_compare_by_value
&& rh
)
211 : val(rh
.val
), ok(rh
.ok
)
213 bool test
__attribute__((unused
)) = true;
218 rvalstruct_compare_by_value
&
219 operator=(rvalstruct_compare_by_value
&& rh
)
221 bool test
__attribute__((unused
)) = true;
231 operator<(rvalstruct_compare_by_value lh
,
232 rvalstruct_compare_by_value rh
)
234 bool test
__attribute__((unused
)) = true;
237 return lh
.val
< rh
.val
;
241 order(rvalstruct_compare_by_value lh
,
242 rvalstruct_compare_by_value rh
)
244 bool test
__attribute__((unused
)) = true;
247 return lh
.val
< rh
.val
;
250 struct throwing_move_constructor
252 throwing_move_constructor() = default;
254 throwing_move_constructor(throwing_move_constructor
&&)
257 throwing_move_constructor(const throwing_move_constructor
&) = default;
259 throwing_move_constructor
&
260 operator=(const throwing_move_constructor
&) = default;
263 } // namespace __gnu_test
267 /// std::hash specialization for __gnu_test::rvalstruct.
269 struct hash
<__gnu_test::rvalstruct
>
271 typedef size_t result_type
;
272 typedef __gnu_test::rvalstruct argument_type
;
275 operator()(const __gnu_test::rvalstruct
& __rvs
) const
276 { return __rvs
.val
; }
280 #endif // _GLIBCXX_TESTSUITE_TR1_H