Marshall Clow | 98760c1 | 2014-01-16 16:58:45 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 10 | #ifndef MOVEONLY_H |
| 11 | #define MOVEONLY_H |
| 12 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 13 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | |
| 15 | #include <cstddef> |
| 16 | #include <functional> |
| 17 | |
| 18 | class MoveOnly |
| 19 | { |
| 20 | MoveOnly(const MoveOnly&); |
| 21 | MoveOnly& operator=(const MoveOnly&); |
| 22 | |
| 23 | int data_; |
| 24 | public: |
David Blaikie | ddcbcd6 | 2014-08-09 22:42:19 +0000 | [diff] [blame] | 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;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | |
| 31 | int get() const {return data_;} |
| 32 | |
Howard Hinnant | 6046ace | 2010-08-22 00:15:28 +0000 | [diff] [blame] | 33 | bool operator==(const MoveOnly& x) const {return data_ == x.data_;} |
| 34 | bool operator< (const MoveOnly& x) const {return data_ < x.data_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | namespace std { |
| 38 | |
| 39 | template <> |
| 40 | struct 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 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 48 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | |
Howard Hinnant | 6046ace | 2010-08-22 00:15:28 +0000 | [diff] [blame] | 50 | #endif // MOVEONLY_H |