blob: a3e9cca89ee501f92fc3d8d03da92c4fc5b0f2ec [file] [log] [blame]
Marshall Clow354d39c2014-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 Hinnant3e519522010-05-11 19:42:16 +000010#ifndef MOVEONLY_H
11#define MOVEONLY_H
12
Eric Fiselierf2f2a632016-06-14 21:31:42 +000013#include "test_macros.h"
14
Howard Hinnant7609c9b2010-09-04 23:28:19 +000015#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +000016
17#include <cstddef>
18#include <functional>
19
20class MoveOnly
21{
Marshall Clowafc9ff92016-01-05 19:32:41 +000022 friend class MoveOnly2;
Howard Hinnant3e519522010-05-11 19:42:16 +000023 MoveOnly(const MoveOnly&);
24 MoveOnly& operator=(const MoveOnly&);
25
26 int data_;
27public:
David Blaikiec6dbc222014-08-09 22:42:19 +000028 MoveOnly(int data = 1) : data_(data) {}
29 MoveOnly(MoveOnly&& x)
30 : data_(x.data_) {x.data_ = 0;}
31 MoveOnly& operator=(MoveOnly&& x)
32 {data_ = x.data_; x.data_ = 0; return *this;}
Howard Hinnant3e519522010-05-11 19:42:16 +000033
34 int get() const {return data_;}
35
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000036 bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
37 bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
Howard Hinnant3e519522010-05-11 19:42:16 +000038};
39
40namespace std {
41
42template <>
43struct hash<MoveOnly>
44 : public std::unary_function<MoveOnly, std::size_t>
45{
46 std::size_t operator()(const MoveOnly& x) const {return x.get();}
47};
48
49}
50
Howard Hinnant7609c9b2010-09-04 23:28:19 +000051#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +000052
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000053#endif // MOVEONLY_H