blob: 34dd326203b0a0078a3092c60dec67621a58b8ee [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
Howard Hinnant7609c9b2010-09-04 23:28:19 +000013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +000014
15class Emplaceable
16{
17 Emplaceable(const Emplaceable&);
18 Emplaceable& operator=(const Emplaceable&);
19
20 int int_;
21 double double_;
22public:
23 Emplaceable() : int_(0), double_(0) {}
24 Emplaceable(int i, double d) : int_(i), double_(d) {}
25 Emplaceable(Emplaceable&& x)
26 : int_(x.int_), double_(x.double_)
27 {x.int_ = 0; x.double_ = 0;}
28 Emplaceable& operator=(Emplaceable&& x)
29 {int_ = x.int_; x.int_ = 0;
30 double_ = x.double_; x.double_ = 0;
31 return *this;}
32
33 bool operator==(const Emplaceable& x) const
34 {return int_ == x.int_ && double_ == x.double_;}
35 bool operator<(const Emplaceable& x) const
Howard Hinnanta7fa0712011-05-13 23:59:50 +000036 {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
Howard Hinnant3e519522010-05-11 19:42:16 +000037
38 int get() const {return int_;}
39};
40
41namespace std {
42
43template <>
44struct hash<Emplaceable>
45 : public std::unary_function<Emplaceable, std::size_t>
46{
47 std::size_t operator()(const Emplaceable& x) const {return x.get();}
48};
49
50}
51
Howard Hinnant7609c9b2010-09-04 23:28:19 +000052#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +000053
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000054#endif // EMPLACEABLE_H