2014-01-17 00:58:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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:
|
2014-08-10 06:42:19 +08:00
|
|
|
MoveOnly(int data = 1) : data_(data) {}
|
|
|
|
MoveOnly(MoveOnly&& x)
|
|
|
|
: data_(x.data_) {x.data_ = 0;}
|
|
|
|
MoveOnly& operator=(MoveOnly&& x)
|
|
|
|
{data_ = x.data_; x.data_ = 0; return *this;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
int get() const {return data_;}
|
|
|
|
|
2010-08-22 08:15:28 +08:00
|
|
|
bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
|
|
|
|
bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
|
2018-01-05 09:32:00 +08:00
|
|
|
MoveOnly operator+(const MoveOnly& x) const { return MoveOnly{data_ + x.data_}; }
|
|
|
|
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;
|
2010-05-12 03:42:16 +08:00
|
|
|
std::size_t operator()(const MoveOnly& x) const {return x.get();}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|