blob: 59ccc66836a5350b212078f05291df4e34945315 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001#ifndef EMPLACEABLE_H
2#define EMPLACEABLE_H
3
Howard Hinnant73d21a42010-09-04 23:28:19 +00004#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005
6class Emplaceable
7{
8 Emplaceable(const Emplaceable&);
9 Emplaceable& operator=(const Emplaceable&);
10
11 int int_;
12 double double_;
13public:
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
32namespace std {
33
34template <>
35struct 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 Hinnant73d21a42010-09-04 23:28:19 +000043#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000044
Howard Hinnant6046ace2010-08-22 00:15:28 +000045#endif // EMPLACEABLE_H