1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 #include "test_macros.h"
21 TEST_CONSTEXPR
MoveOnly(int data
= 1) : data_(data
) {}
23 MoveOnly(const MoveOnly
&) = delete;
24 MoveOnly
& operator=(const MoveOnly
&) = delete;
26 TEST_CONSTEXPR_CXX14
MoveOnly(MoveOnly
&& x
) TEST_NOEXCEPT
27 : data_(x
.data_
) {x
.data_
= 0;}
28 TEST_CONSTEXPR_CXX14 MoveOnly
& operator=(MoveOnly
&& x
)
29 {data_
= x
.data_
; x
.data_
= 0; return *this;}
31 TEST_CONSTEXPR
int get() const {return data_
;}
33 friend TEST_CONSTEXPR
bool operator==(const MoveOnly
& x
, const MoveOnly
& y
)
34 { return x
.data_
== y
.data_
; }
35 friend TEST_CONSTEXPR
bool operator!=(const MoveOnly
& x
, const MoveOnly
& y
)
36 { return x
.data_
!= y
.data_
; }
37 friend TEST_CONSTEXPR
bool operator< (const MoveOnly
& x
, const MoveOnly
& y
)
38 { return x
.data_
< y
.data_
; }
39 friend TEST_CONSTEXPR
bool operator<=(const MoveOnly
& x
, const MoveOnly
& y
)
40 { return x
.data_
<= y
.data_
; }
41 friend TEST_CONSTEXPR
bool operator> (const MoveOnly
& x
, const MoveOnly
& y
)
42 { return x
.data_
> y
.data_
; }
43 friend TEST_CONSTEXPR
bool operator>=(const MoveOnly
& x
, const MoveOnly
& y
)
44 { return x
.data_
>= y
.data_
; }
47 friend constexpr auto operator<=>(const MoveOnly
&, const MoveOnly
&) = default;
48 #endif // TEST_STD_VER > 17
50 TEST_CONSTEXPR_CXX14 MoveOnly
operator+(const MoveOnly
& x
) const
51 { return MoveOnly(data_
+ x
.data_
); }
52 TEST_CONSTEXPR_CXX14 MoveOnly
operator*(const MoveOnly
& x
) const
53 { return MoveOnly(data_
* x
.data_
); }
56 friend void operator,(MoveOnly
const&, T
) = delete;
59 friend void operator,(T
, MoveOnly
const&) = delete;
63 struct std::hash
<MoveOnly
>
65 typedef MoveOnly argument_type
;
66 typedef std::size_t result_type
;
67 TEST_CONSTEXPR
std::size_t operator()(const MoveOnly
& x
) const {return static_cast<size_t>(x
.get());}
70 class TrivialMoveOnly
{
74 TEST_CONSTEXPR
TrivialMoveOnly(int data
= 1) : data_(data
) {}
76 TrivialMoveOnly(const TrivialMoveOnly
&) = delete;
77 TrivialMoveOnly
& operator=(const TrivialMoveOnly
&) = delete;
79 TrivialMoveOnly(TrivialMoveOnly
&&) = default;
80 TrivialMoveOnly
& operator=(TrivialMoveOnly
&&) = default;
82 TEST_CONSTEXPR
int get() const { return data_
; }
84 friend TEST_CONSTEXPR
bool operator==(const TrivialMoveOnly
& x
, const TrivialMoveOnly
& y
) {
85 return x
.data_
== y
.data_
;
87 friend TEST_CONSTEXPR
bool operator!=(const TrivialMoveOnly
& x
, const TrivialMoveOnly
& y
) {
88 return x
.data_
!= y
.data_
;
90 friend TEST_CONSTEXPR
bool operator<(const TrivialMoveOnly
& x
, const TrivialMoveOnly
& y
) {
91 return x
.data_
< y
.data_
;
93 friend TEST_CONSTEXPR
bool operator<=(const TrivialMoveOnly
& x
, const TrivialMoveOnly
& y
) {
94 return x
.data_
<= y
.data_
;
96 friend TEST_CONSTEXPR
bool operator>(const TrivialMoveOnly
& x
, const TrivialMoveOnly
& y
) {
97 return x
.data_
> y
.data_
;
99 friend TEST_CONSTEXPR
bool operator>=(const TrivialMoveOnly
& x
, const TrivialMoveOnly
& y
) {
100 return x
.data_
>= y
.data_
;
103 #if TEST_STD_VER > 17
104 friend constexpr auto operator<=>(const TrivialMoveOnly
&, const TrivialMoveOnly
&) = default;
105 #endif // TEST_STD_VER > 17
107 TEST_CONSTEXPR_CXX14 TrivialMoveOnly
operator+(const TrivialMoveOnly
& x
) const {
108 return TrivialMoveOnly(data_
+ x
.data_
);
110 TEST_CONSTEXPR_CXX14 TrivialMoveOnly
operator*(const TrivialMoveOnly
& x
) const {
111 return TrivialMoveOnly(data_
* x
.data_
);
115 friend void operator,(TrivialMoveOnly
const&, T
) = delete;
118 friend void operator,(T
, TrivialMoveOnly
const&) = delete;
122 struct std::hash
<TrivialMoveOnly
> {
123 typedef TrivialMoveOnly argument_type
;
124 typedef std::size_t result_type
;
125 TEST_CONSTEXPR
std::size_t operator()(const TrivialMoveOnly
& x
) const { return static_cast<size_t>(x
.get()); }