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"
14 #if TEST_STD_VER >= 11
23 constexpr MoveOnly(int data
= 1) : data_(data
) {}
24 TEST_CONSTEXPR_CXX14
MoveOnly(MoveOnly
&& x
)
25 : data_(x
.data_
) {x
.data_
= 0;}
26 TEST_CONSTEXPR_CXX14 MoveOnly
& operator=(MoveOnly
&& x
)
27 {data_
= x
.data_
; x
.data_
= 0; return *this;}
29 constexpr int get() const {return data_
;}
31 friend constexpr bool operator==(const MoveOnly
& x
, const MoveOnly
& y
)
32 { return x
.data_
== y
.data_
; }
33 friend constexpr bool operator!=(const MoveOnly
& x
, const MoveOnly
& y
)
34 { return x
.data_
!= y
.data_
; }
35 friend constexpr bool operator< (const MoveOnly
& x
, const MoveOnly
& y
)
36 { return x
.data_
< y
.data_
; }
37 friend constexpr bool operator<=(const MoveOnly
& x
, const MoveOnly
& y
)
38 { return x
.data_
<= y
.data_
; }
39 friend constexpr bool operator> (const MoveOnly
& x
, const MoveOnly
& y
)
40 { return x
.data_
> y
.data_
; }
41 friend constexpr bool operator>=(const MoveOnly
& x
, const MoveOnly
& y
)
42 { return x
.data_
>= y
.data_
; }
44 TEST_CONSTEXPR_CXX14 MoveOnly
operator+(const MoveOnly
& x
) const
45 { return MoveOnly
{data_
+ x
.data_
}; }
46 TEST_CONSTEXPR_CXX14 MoveOnly
operator*(const MoveOnly
& x
) const
47 { return MoveOnly
{data_
* x
.data_
}; }
49 template<class T
, class U
>
50 friend void operator,(T t
, U u
) = delete;
55 struct std::hash
<MoveOnly
>
57 typedef MoveOnly argument_type
;
58 typedef size_t result_type
;
59 constexpr size_t operator()(const MoveOnly
& x
) const {return x
.get();}
62 #endif // TEST_STD_VER >= 11