[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / support / MoveOnly.h
blobadcae2542bd3c761a21c9e1f72e05dcded068d42
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef MOVEONLY_H
10 #define MOVEONLY_H
12 #include "test_macros.h"
14 #if TEST_STD_VER >= 11
16 #include <cstddef>
17 #include <functional>
19 class MoveOnly
21 MoveOnly(const MoveOnly&);
22 MoveOnly& operator=(const MoveOnly&);
24 int data_;
25 public:
26 constexpr MoveOnly(int data = 1) : data_(data) {}
27 TEST_CONSTEXPR_CXX14 MoveOnly(MoveOnly&& x)
28 : data_(x.data_) {x.data_ = 0;}
29 TEST_CONSTEXPR_CXX14 MoveOnly& operator=(MoveOnly&& x)
30 {data_ = x.data_; x.data_ = 0; return *this;}
32 constexpr int get() const {return data_;}
34 constexpr bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
35 constexpr bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
36 TEST_CONSTEXPR_CXX14 MoveOnly operator+(const MoveOnly& x) const
37 { return MoveOnly{data_ + x.data_}; }
38 TEST_CONSTEXPR_CXX14 MoveOnly operator*(const MoveOnly& x) const
39 { return MoveOnly{data_ * x.data_}; }
42 namespace std {
44 template <>
45 struct hash<MoveOnly>
47 typedef MoveOnly argument_type;
48 typedef size_t result_type;
49 constexpr std::size_t operator()(const MoveOnly& x) const {return x.get();}
54 #endif // TEST_STD_VER >= 11
56 #endif // MOVEONLY_H