2014-01-17 00:58:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// 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
|
2014-01-17 00:58:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef MOVEONLY_H
|
|
|
|
#define MOVEONLY_H
|
|
|
|
|
2016-06-15 05:31:42 +08:00
|
|
|
#include "test_macros.h"
|
|
|
|
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
class MoveOnly
|
|
|
|
{
|
|
|
|
int data_;
|
|
|
|
public:
|
2020-05-22 23:20:27 +08:00
|
|
|
constexpr MoveOnly(int data = 1) : data_(data) {}
|
2020-05-24 05:43:12 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 MoveOnly(MoveOnly&& x)
|
2014-08-10 06:42:19 +08:00
|
|
|
: data_(x.data_) {x.data_ = 0;}
|
2020-05-24 05:43:12 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 MoveOnly& operator=(MoveOnly&& x)
|
2014-08-10 06:42:19 +08:00
|
|
|
{data_ = x.data_; x.data_ = 0; return *this;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2020-05-22 23:20:27 +08:00
|
|
|
constexpr int get() const {return data_;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-01-29 06:24:31 +08:00
|
|
|
friend constexpr bool operator==(const MoveOnly& x, const MoveOnly& y)
|
|
|
|
{ return x.data_ == y.data_; }
|
|
|
|
friend constexpr bool operator!=(const MoveOnly& x, const MoveOnly& y)
|
|
|
|
{ return x.data_ != y.data_; }
|
|
|
|
friend constexpr bool operator< (const MoveOnly& x, const MoveOnly& y)
|
|
|
|
{ return x.data_ < y.data_; }
|
|
|
|
friend constexpr bool operator<=(const MoveOnly& x, const MoveOnly& y)
|
|
|
|
{ return x.data_ <= y.data_; }
|
|
|
|
friend constexpr bool operator> (const MoveOnly& x, const MoveOnly& y)
|
|
|
|
{ return x.data_ > y.data_; }
|
|
|
|
friend constexpr bool operator>=(const MoveOnly& x, const MoveOnly& y)
|
|
|
|
{ return x.data_ >= y.data_; }
|
|
|
|
|
2020-05-24 05:43:12 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 MoveOnly operator+(const MoveOnly& x) const
|
|
|
|
{ return MoveOnly{data_ + x.data_}; }
|
|
|
|
TEST_CONSTEXPR_CXX14 MoveOnly operator*(const MoveOnly& x) const
|
|
|
|
{ return MoveOnly{data_ * x.data_}; }
|
2021-09-08 09:35:37 +08:00
|
|
|
|
|
|
|
template<class T, class U>
|
|
|
|
friend void operator,(T t, U u) = delete;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
2022-01-29 03:38:10 +08:00
|
|
|
struct std::hash<MoveOnly>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2017-01-18 09:48:54 +08:00
|
|
|
typedef MoveOnly argument_type;
|
|
|
|
typedef size_t result_type;
|
2021-01-29 06:24:31 +08:00
|
|
|
constexpr size_t operator()(const MoveOnly& x) const {return x.get();}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // TEST_STD_VER >= 11
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // MOVEONLY_H
|