2 // Testing utilities for the rvalue reference.
4 // Copyright (C) 2005-2017 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>
26 #include <bits/functional_hash.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
32 // attempt to copy it.
38 rvalstruct() : val(0), valid(true)
41 rvalstruct(int inval
) : val(inval
), valid(true)
52 rvalstruct(const rvalstruct
&) = delete;
54 rvalstruct(rvalstruct
&& in
)
56 VERIFY( in
.valid
== true );
63 operator=(const rvalstruct
&) = delete;
66 operator=(rvalstruct
&& in
)
68 VERIFY( this != &in
);
69 VERIFY( in
.valid
== true );
78 operator==(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
79 { return lhs
.val
== rhs
.val
; }
82 operator<(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
83 { return lhs
.val
< rhs
.val
; }
86 swap(rvalstruct
& lhs
, rvalstruct
& rhs
)
88 VERIFY( lhs
.valid
&& rhs
.valid
);
94 // This is a moveable class which copies how many times it is copied.
95 // This is mainly of use in the containers, where the an element inserted
96 // into a container has to be copied once to get there, but we want to check
97 // nothing else is copied.
100 static int copycount
;
104 copycounter() : val(0), valid(true)
107 copycounter(int inval
) : val(inval
), valid(true)
110 copycounter(const copycounter
& in
) : val(in
.val
), valid(true)
112 VERIFY( in
.valid
== true );
116 copycounter(copycounter
&& in
) noexcept
118 VERIFY( in
.valid
== true );
125 operator=(int newval
)
133 operator=(const copycounter
& in
)
135 VERIFY( in
.valid
== true );
143 operator=(copycounter
&& in
)
145 VERIFY(in
.valid
== true);
152 ~copycounter() noexcept
156 int copycounter::copycount
= 0;
159 operator==(const copycounter
& lhs
, const copycounter
& rhs
)
160 { return lhs
.val
== rhs
.val
; }
163 operator<(const copycounter
& lhs
, const copycounter
& rhs
)
164 { return lhs
.val
< rhs
.val
; }
167 swap(copycounter
& lhs
, copycounter
& rhs
)
169 VERIFY( lhs
.valid
&& rhs
.valid
);
175 // In the occasion of libstdc++/48038.
176 struct rvalstruct_compare_by_value
181 rvalstruct_compare_by_value(int v
)
182 : val(v
), ok(true) { }
184 rvalstruct_compare_by_value(const rvalstruct_compare_by_value
& rh
)
185 : val(rh
.val
), ok(rh
.ok
)
190 rvalstruct_compare_by_value
&
191 operator=(const rvalstruct_compare_by_value
& rh
)
199 rvalstruct_compare_by_value(rvalstruct_compare_by_value
&& rh
)
200 : val(rh
.val
), ok(rh
.ok
)
206 rvalstruct_compare_by_value
&
207 operator=(rvalstruct_compare_by_value
&& rh
)
218 operator<(rvalstruct_compare_by_value lh
,
219 rvalstruct_compare_by_value rh
)
223 return lh
.val
< rh
.val
;
227 order(rvalstruct_compare_by_value lh
,
228 rvalstruct_compare_by_value rh
)
232 return lh
.val
< rh
.val
;
235 struct throwing_move_constructor
237 throwing_move_constructor() = default;
239 throwing_move_constructor(throwing_move_constructor
&&)
242 throwing_move_constructor(const throwing_move_constructor
&) = default;
244 throwing_move_constructor
&
245 operator=(const throwing_move_constructor
&) = default;
248 } // namespace __gnu_test
252 /// std::hash specialization for __gnu_test::rvalstruct.
254 struct hash
<__gnu_test::rvalstruct
>
256 typedef size_t result_type
;
257 typedef __gnu_test::rvalstruct argument_type
;
260 operator()(const __gnu_test::rvalstruct
& __rvs
) const
261 { return __rvs
.val
; }
265 #endif // _GLIBCXX_TESTSUITE_TR1_H