blob: 331a81ff311f8763764c898576ea6561b7958a3f [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 EMPLACEABLE_H
11#define EMPLACEABLE_H
12
Eric Fiselier6a470bc2017-04-18 22:50:56 +000013#include <utility>
14#include "test_macros.h"
15
16#if TEST_STD_VER >= 11
Howard Hinnant3e519522010-05-11 19:42:16 +000017
18class Emplaceable
19{
20 Emplaceable(const Emplaceable&);
21 Emplaceable& operator=(const Emplaceable&);
22
23 int int_;
24 double double_;
25public:
26 Emplaceable() : int_(0), double_(0) {}
27 Emplaceable(int i, double d) : int_(i), double_(d) {}
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
Howard Hinnanta7fa0712011-05-13 23:59:50 +000039 {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
Howard Hinnant3e519522010-05-11 19:42:16 +000040
41 int get() const {return int_;}
42};
43
44namespace std {
45
46template <>
47struct hash<Emplaceable>
Howard Hinnant3e519522010-05-11 19:42:16 +000048{
Stephan T. Lavavejbc933762017-08-24 21:24:08 +000049 typedef Emplaceable argument_type;
50 typedef std::size_t result_type;
51
Howard Hinnant3e519522010-05-11 19:42:16 +000052 std::size_t operator()(const Emplaceable& x) const {return x.get();}
53};
54
55}
56
Eric Fiselier6a470bc2017-04-18 22:50:56 +000057#endif // TEST_STD_VER >= 11
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000058#endif // EMPLACEABLE_H