[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349
[llvm-project.git] / libcxx / test / support / MoveOnly.h
blob33557773e9195e33f390887ddeba7687b3c555b5
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 int data_;
22 public:
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;
54 template <>
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
64 #endif // MOVEONLY_H