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
|
|
|
|
{
|
|
|
|
MoveOnly(const MoveOnly&);
|
|
|
|
MoveOnly& operator=(const MoveOnly&);
|
|
|
|
|
|
|
|
int data_;
|
|
|
|
public:
|
2020-05-22 23:20:27 +08:00
|
|
|
constexpr MoveOnly(int data = 1) : data_(data) {}
|
|
|
|
constexpr MoveOnly(MoveOnly&& x)
|
2014-08-10 06:42:19 +08:00
|
|
|
: data_(x.data_) {x.data_ = 0;}
|
2020-05-22 23:20:27 +08:00
|
|
|
constexpr 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
|
|
|
|
2020-05-22 23:20:27 +08:00
|
|
|
constexpr bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
|
|
|
|
constexpr bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
|
|
|
|
constexpr MoveOnly operator+(const MoveOnly& x) const { return MoveOnly{data_ + x.data_}; }
|
|
|
|
constexpr MoveOnly operator*(const MoveOnly& x) const { return MoveOnly{data_ * x.data_}; }
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct hash<MoveOnly>
|
|
|
|
{
|
2017-01-18 09:48:54 +08:00
|
|
|
typedef MoveOnly argument_type;
|
|
|
|
typedef size_t result_type;
|
2020-05-22 23:20:27 +08:00
|
|
|
constexpr std::size_t operator()(const MoveOnly& x) const {return x.get();}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-19 09:02:49 +08:00
|
|
|
#endif // TEST_STD_VER >= 11
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-22 08:15:28 +08:00
|
|
|
#endif // MOVEONLY_H
|