blob: e4d9f649560235e7836e68534372115686180111 [file] [log] [blame]
Marshall Clow98760c12014-01-16 16:58:45 +00001//===----------------------------------------------------------------------===//
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 Hinnantbc8d3f92010-05-11 19:42:16 +000010#ifndef MOVEONLY_H
11#define MOVEONLY_H
12
Howard Hinnant73d21a42010-09-04 23:28:19 +000013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000014
15#include <cstddef>
16#include <functional>
17
18class MoveOnly
19{
20 MoveOnly(const MoveOnly&);
21 MoveOnly& operator=(const MoveOnly&);
22
23 int data_;
24public:
David Blaikieddcbcd62014-08-09 22:42:19 +000025 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 Hinnantbc8d3f92010-05-11 19:42:16 +000030
31 int get() const {return data_;}
32
Howard Hinnant6046ace2010-08-22 00:15:28 +000033 bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
34 bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000035};
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
Howard Hinnant73d21a42010-09-04 23:28:19 +000048#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049
Howard Hinnant6046ace2010-08-22 00:15:28 +000050#endif // MOVEONLY_H