• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "test_macros.h"
14 
15 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
16 
17 #include <cstddef>
18 #include <functional>
19 
20 class MoveOnly
21 {
22     friend class MoveOnly2;
23     MoveOnly(const MoveOnly&);
24     MoveOnly& operator=(const MoveOnly&);
25 
26     int data_;
27 public:
data_(data)28     MoveOnly(int data = 1) : data_(data) {}
MoveOnly(MoveOnly && x)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;}
33 
get()34     int get() const {return data_;}
35 
36     bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
37     bool operator< (const MoveOnly& x) const {return data_ <  x.data_;}
38 };
39 
40 namespace std {
41 
42 template <>
43 struct hash<MoveOnly>
44 {
45     typedef MoveOnly argument_type;
46     typedef size_t result_type;
47     std::size_t operator()(const MoveOnly& x) const {return x.get();}
48 };
49 
50 }
51 
52 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
53 
54 #endif  // MOVEONLY_H
55