2014-01-16 17:58:45 +01: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-11 21:42:16 +02:00
|
|
|
#ifndef MOVEONLY_H
|
|
|
|
#define MOVEONLY_H
|
|
|
|
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
class MoveOnly
|
|
|
|
{
|
|
|
|
MoveOnly(const MoveOnly&);
|
|
|
|
MoveOnly& operator=(const MoveOnly&);
|
|
|
|
|
|
|
|
int data_;
|
|
|
|
public:
|
2014-08-10 00:42:19 +02: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-11 21:42:16 +02:00
|
|
|
|
|
|
|
int get() const {return data_;}
|
|
|
|
|
2010-08-22 02:15:28 +02:00
|
|
|
bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
|
|
|
|
bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
|
2010-05-11 21:42:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct hash<MoveOnly>
|
|
|
|
: public std::unary_function<MoveOnly, std::size_t>
|
|
|
|
{
|
|
|
|
std::size_t operator()(const MoveOnly& x) const {return x.get();}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-05 01:28:19 +02:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2010-08-22 02:15:28 +02:00
|
|
|
#endif // MOVEONLY_H
|