1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef MOVEONLY_H 11#define MOVEONLY_H 12 13#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 14 15#include <cstddef> 16#include <functional> 17 18class MoveOnly 19{ 20 MoveOnly(const MoveOnly&); 21 MoveOnly& operator=(const MoveOnly&); 22 23 int data_; 24public: 25 MoveOnly(int data = 1) : data_(data) {} 26 MoveOnly(MoveOnly&& x) 27 : data_(x.data_) {x.data_ = 0;} 28 MoveOnly& operator=(MoveOnly&& x) 29 {data_ = x.data_; x.data_ = 0; return *this;} 30 31 int get() const {return data_;} 32 33 bool operator==(const MoveOnly& x) const {return data_ == x.data_;} 34 bool operator< (const MoveOnly& x) const {return data_ < x.data_;} 35}; 36 37namespace std { 38 39template <> 40struct hash<MoveOnly> 41 : public std::unary_function<MoveOnly, std::size_t> 42{ 43 std::size_t operator()(const MoveOnly& x) const {return x.get();} 44}; 45 46} 47 48#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 49 50#endif // MOVEONLY_H 51