• 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 EMPLACEABLE_H
11 #define EMPLACEABLE_H
12 
13 #include <functional>
14 #include "test_macros.h"
15 
16 #if TEST_STD_VER >= 11
17 
18 class Emplaceable
19 {
20     Emplaceable(const Emplaceable&);
21     Emplaceable& operator=(const Emplaceable&);
22 
23     int int_;
24     double double_;
25 public:
Emplaceable()26     Emplaceable() : int_(0), double_(0) {}
Emplaceable(int i,double d)27     Emplaceable(int i, double d) : int_(i), double_(d) {}
Emplaceable(Emplaceable && x)28     Emplaceable(Emplaceable&& x)
29         : int_(x.int_), double_(x.double_)
30             {x.int_ = 0; x.double_ = 0;}
31     Emplaceable& operator=(Emplaceable&& x)
32         {int_ = x.int_; x.int_ = 0;
33          double_ = x.double_; x.double_ = 0;
34          return *this;}
35 
36     bool operator==(const Emplaceable& x) const
37         {return int_ == x.int_ && double_ == x.double_;}
38     bool operator<(const Emplaceable& x) const
39         {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
40 
get()41     int get() const {return int_;}
42 };
43 
44 namespace std {
45 
46 template <>
47 struct hash<Emplaceable>
48 {
49     typedef Emplaceable argument_type;
50     typedef std::size_t result_type;
51 
52     std::size_t operator()(const Emplaceable& x) const {return x.get();}
53 };
54 
55 }
56 
57 #endif  // TEST_STD_VER >= 11
58 #endif  // EMPLACEABLE_H
59