Marshall Clow | 354d39c | 2014-01-16 16:58:45 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 10 | #ifndef EMPLACEABLE_H |
| 11 | #define EMPLACEABLE_H |
| 12 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 +0000 | [diff] [blame] | 13 | #include <utility> |
| 14 | #include "test_macros.h" |
| 15 | |
| 16 | #if TEST_STD_VER >= 11 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 17 | |
| 18 | class Emplaceable |
| 19 | { |
| 20 | Emplaceable(const Emplaceable&); |
| 21 | Emplaceable& operator=(const Emplaceable&); |
| 22 | |
| 23 | int int_; |
| 24 | double double_; |
| 25 | public: |
| 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 Hinnant | a7fa071 | 2011-05-13 23:59:50 +0000 | [diff] [blame] | 39 | {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | |
| 41 | int get() const {return int_;} |
| 42 | }; |
| 43 | |
| 44 | namespace std { |
| 45 | |
| 46 | template <> |
| 47 | struct hash<Emplaceable> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | { |
Stephan T. Lavavej | bc93376 | 2017-08-24 21:24:08 +0000 | [diff] [blame] | 49 | typedef Emplaceable argument_type; |
| 50 | typedef std::size_t result_type; |
| 51 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | std::size_t operator()(const Emplaceable& x) const {return x.get();} |
| 53 | }; |
| 54 | |
| 55 | } |
| 56 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 +0000 | [diff] [blame] | 57 | #endif // TEST_STD_VER >= 11 |
Howard Hinnant | 8f2f7e7 | 2010-08-22 00:15:28 +0000 | [diff] [blame] | 58 | #endif // EMPLACEABLE_H |