| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#ifndef EMPLACEABLE_H |
| 10 |
#define EMPLACEABLE_H |
| 11 |
|
| 12 |
#include <functional> |
| 13 |
#include "test_macros.h" |
| 14 |
|
| 15 |
#if TEST_STD_VER >= 11 |
| 16 |
|
| 17 |
class Emplaceable |
| 18 |
{ |
| 19 |
Emplaceable(const Emplaceable&); |
| 20 |
Emplaceable& operator=(const Emplaceable&); |
| 21 |
|
| 22 |
int int_; |
| 23 |
double double_; |
| 24 |
public: |
| 25 |
Emplaceable() : int_(0), double_(0) {} |
| 26 |
Emplaceable(int i, double d) : int_(i), double_(d) {} |
| 27 |
Emplaceable(Emplaceable&& x) |
| 28 |
: int_(x.int_), double_(x.double_) |
| 29 |
{x.int_ = 0; x.double_ = 0;} |
| 30 |
Emplaceable& operator=(Emplaceable&& x) |
| 31 |
{int_ = x.int_; x.int_ = 0; |
| 32 |
double_ = x.double_; x.double_ = 0; |
| 33 |
return *this;} |
| 34 |
|
| 35 |
bool operator==(const Emplaceable& x) const |
| 36 |
{return int_ == x.int_ && double_ == x.double_;} |
| 37 |
bool operator<(const Emplaceable& x) const |
| 38 |
{return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);} |
| 39 |
|
| 40 |
int get() const {return int_;} |
| 41 |
}; |
| 42 |
|
| 43 |
namespace std { |
| 44 |
|
| 45 |
template <> |
| 46 |
struct hash<Emplaceable> |
| 47 |
{ |
| 48 |
typedef Emplaceable argument_type; |
| 49 |
typedef std::size_t result_type; |
| 50 |
|
| 51 |
std::size_t operator()(const Emplaceable& x) const {return x.get();} |
| 52 |
}; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
#endif // TEST_STD_VER >= 11 |
| 57 |
#endif // EMPLACEABLE_H |