1*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===// 2*0a6a1f1dSLionel Sambuc // 3*0a6a1f1dSLionel Sambuc // The LLVM Compiler Infrastructure 4*0a6a1f1dSLionel Sambuc // 5*0a6a1f1dSLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open 6*0a6a1f1dSLionel Sambuc // Source Licenses. See LICENSE.TXT for details. 7*0a6a1f1dSLionel Sambuc // 8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===// 9*0a6a1f1dSLionel Sambuc 104684ddb6SLionel Sambuc #ifndef MOVEONLY_H 114684ddb6SLionel Sambuc #define MOVEONLY_H 124684ddb6SLionel Sambuc 134684ddb6SLionel Sambuc #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 144684ddb6SLionel Sambuc 154684ddb6SLionel Sambuc #include <cstddef> 164684ddb6SLionel Sambuc #include <functional> 174684ddb6SLionel Sambuc 184684ddb6SLionel Sambuc class MoveOnly 194684ddb6SLionel Sambuc { 204684ddb6SLionel Sambuc MoveOnly(const MoveOnly&); 214684ddb6SLionel Sambuc MoveOnly& operator=(const MoveOnly&); 224684ddb6SLionel Sambuc 234684ddb6SLionel Sambuc int data_; 244684ddb6SLionel Sambuc public: data_(data)254684ddb6SLionel Sambuc MoveOnly(int data = 1) : data_(data) {} MoveOnly(MoveOnly && x)264684ddb6SLionel Sambuc MoveOnly(MoveOnly&& x) 274684ddb6SLionel Sambuc : data_(x.data_) {x.data_ = 0;} 284684ddb6SLionel Sambuc MoveOnly& operator=(MoveOnly&& x) 294684ddb6SLionel Sambuc {data_ = x.data_; x.data_ = 0; return *this;} 304684ddb6SLionel Sambuc get()314684ddb6SLionel Sambuc int get() const {return data_;} 324684ddb6SLionel Sambuc 334684ddb6SLionel Sambuc bool operator==(const MoveOnly& x) const {return data_ == x.data_;} 344684ddb6SLionel Sambuc bool operator< (const MoveOnly& x) const {return data_ < x.data_;} 354684ddb6SLionel Sambuc }; 364684ddb6SLionel Sambuc 374684ddb6SLionel Sambuc namespace std { 384684ddb6SLionel Sambuc 394684ddb6SLionel Sambuc template <> 404684ddb6SLionel Sambuc struct hash<MoveOnly> 414684ddb6SLionel Sambuc : public std::unary_function<MoveOnly, std::size_t> 424684ddb6SLionel Sambuc { 434684ddb6SLionel Sambuc std::size_t operator()(const MoveOnly& x) const {return x.get();} 444684ddb6SLionel Sambuc }; 454684ddb6SLionel Sambuc 464684ddb6SLionel Sambuc } 474684ddb6SLionel Sambuc 484684ddb6SLionel Sambuc #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 494684ddb6SLionel Sambuc 504684ddb6SLionel Sambuc #endif // MOVEONLY_H 51