• 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 #if TEST_STD_VER >= 11
16 
17 #include <cstddef>
18 #include <functional>
19 
20 class MoveOnly
21 {
22     MoveOnly(const MoveOnly&);
23     MoveOnly& operator=(const MoveOnly&);
24 
25     int data_;
26 public:
data_(data)27     MoveOnly(int data = 1) : data_(data) {}
MoveOnly(MoveOnly && x)28     MoveOnly(MoveOnly&& x)
29         : data_(x.data_) {x.data_ = 0;}
30     MoveOnly& operator=(MoveOnly&& x)
31         {data_ = x.data_; x.data_ = 0; return *this;}
32 
get()33     int get() const {return data_;}
34 
35     bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
36     bool operator< (const MoveOnly& x) const {return data_ <  x.data_;}
37     MoveOnly operator+(const MoveOnly& x) const { return MoveOnly{data_ + x.data_}; }
38     MoveOnly operator*(const MoveOnly& x) const { return MoveOnly{data_ * x.data_}; }
39 };
40 
41 namespace std {
42 
43 template <>
44 struct hash<MoveOnly>
45 {
46     typedef MoveOnly argument_type;
47     typedef size_t result_type;
48     std::size_t operator()(const MoveOnly& x) const {return x.get();}
49 };
50 
51 }
52 
53 #endif  // TEST_STD_VER >= 11
54 
55 #endif  // MOVEONLY_H
56