//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES // //===----------------------------------------------------------------------===// #ifndef MOVEONLY_H #define MOVEONLY_H #include #include "test_macros.h" // #include class MoveOnly { int data_; public: TEST_FUNC constexpr MoveOnly(int data = 1) : data_(data) {} MoveOnly(const MoveOnly&) = delete; MoveOnly& operator=(const MoveOnly&) = delete; TEST_FUNC constexpr MoveOnly(MoveOnly&& x) : data_(x.data_) { x.data_ = 0; } TEST_FUNC constexpr MoveOnly& operator=(MoveOnly&& x) { data_ = x.data_; x.data_ = 0; return *this; } TEST_FUNC constexpr int get() const { return data_; } TEST_FUNC friend constexpr bool operator==(const MoveOnly& x, const MoveOnly& y) { return x.data_ == y.data_; } TEST_FUNC friend constexpr bool operator!=(const MoveOnly& x, const MoveOnly& y) { return x.data_ != y.data_; } TEST_FUNC friend constexpr bool operator<(const MoveOnly& x, const MoveOnly& y) { return x.data_ < y.data_; } TEST_FUNC friend constexpr bool operator<=(const MoveOnly& x, const MoveOnly& y) { return x.data_ <= y.data_; } TEST_FUNC friend constexpr bool operator>(const MoveOnly& x, const MoveOnly& y) { return x.data_ > y.data_; } TEST_FUNC friend constexpr bool operator>=(const MoveOnly& x, const MoveOnly& y) { return x.data_ >= y.data_; } #if TEST_STD_VER > 2017 && _LIBCUDACXX_HAS_SPACESHIP_OPERATOR() TEST_FUNC friend constexpr auto operator<=>(const MoveOnly&, const MoveOnly&) = default; #endif // TEST_STD_VER > 2017 && _LIBCUDACXX_HAS_SPACESHIP_OPERATOR() TEST_FUNC constexpr MoveOnly operator+(const MoveOnly& x) const { return MoveOnly(data_ + x.data_); } TEST_FUNC constexpr MoveOnly operator*(const MoveOnly& x) const { return MoveOnly(data_ * x.data_); } template void operator,(T const&) = delete; }; /* template <> struct cuda::std::hash { using argument_type = MoveOnly; using result_type = size_t; TEST_FUNC constexpr size_t operator()(const MoveOnly& x) const {return x.get();} }; */ #endif // MOVEONLY_H