Home | History | Annotate | Download | only in support
      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     friend class MoveOnly2;
     23     MoveOnly(const MoveOnly&);
     24     MoveOnly& operator=(const MoveOnly&);
     25 
     26     int data_;
     27 public:
     28     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;}
     33 
     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  // TEST_STD_VER >= 11
     53 
     54 #endif  // MOVEONLY_H
     55