Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | #ifndef EMPLACEABLE_H |
| 2 | #define EMPLACEABLE_H |
| 3 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 4 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | |
| 6 | class Emplaceable |
| 7 | { |
| 8 | Emplaceable(const Emplaceable&); |
| 9 | Emplaceable& operator=(const Emplaceable&); |
| 10 | |
| 11 | int int_; |
| 12 | double double_; |
| 13 | public: |
| 14 | Emplaceable() : int_(0), double_(0) {} |
| 15 | Emplaceable(int i, double d) : int_(i), double_(d) {} |
| 16 | Emplaceable(Emplaceable&& x) |
| 17 | : int_(x.int_), double_(x.double_) |
| 18 | {x.int_ = 0; x.double_ = 0;} |
| 19 | Emplaceable& operator=(Emplaceable&& x) |
| 20 | {int_ = x.int_; x.int_ = 0; |
| 21 | double_ = x.double_; x.double_ = 0; |
| 22 | return *this;} |
| 23 | |
| 24 | bool operator==(const Emplaceable& x) const |
| 25 | {return int_ == x.int_ && double_ == x.double_;} |
| 26 | bool operator<(const Emplaceable& x) const |
| 27 | {return int_ < x.int_ || int_ == x.int_ && double_ < x.double_;} |
| 28 | |
| 29 | int get() const {return int_;} |
| 30 | }; |
| 31 | |
| 32 | namespace std { |
| 33 | |
| 34 | template <> |
| 35 | struct hash<Emplaceable> |
| 36 | : public std::unary_function<Emplaceable, std::size_t> |
| 37 | { |
| 38 | std::size_t operator()(const Emplaceable& x) const {return x.get();} |
| 39 | }; |
| 40 | |
| 41 | } |
| 42 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 43 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | |
Howard Hinnant | 6046ace | 2010-08-22 00:15:28 +0000 | [diff] [blame] | 45 | #endif // EMPLACEABLE_H |