Home | History | Annotate | Download | only in containers
      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 
     10 #ifndef EMPLACEABLE_H
     11 #define EMPLACEABLE_H
     12 
     13 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     14 
     15 class Emplaceable
     16 {
     17 #if !defined(__clang__)
     18 // GCC 4.8 when compile ccontainers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp, etc,
     19 // complains about the following being private
     20 public:
     21     Emplaceable(const Emplaceable&) {}
     22 #else
     23     Emplaceable(const Emplaceable&);
     24 #endif
     25     Emplaceable& operator=(const Emplaceable&);
     26 
     27     int int_;
     28     double double_;
     29 public:
     30     Emplaceable() : int_(0), double_(0) {}
     31     Emplaceable(int i, double d) : int_(i), double_(d) {}
     32     Emplaceable(Emplaceable&& x)
     33         : int_(x.int_), double_(x.double_)
     34             {x.int_ = 0; x.double_ = 0;}
     35     Emplaceable& operator=(Emplaceable&& x)
     36         {int_ = x.int_; x.int_ = 0;
     37          double_ = x.double_; x.double_ = 0;
     38          return *this;}
     39 
     40     bool operator==(const Emplaceable& x) const
     41         {return int_ == x.int_ && double_ == x.double_;}
     42     bool operator<(const Emplaceable& x) const
     43         {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
     44 
     45     int get() const {return int_;}
     46 };
     47 
     48 namespace std {
     49 
     50 template <>
     51 struct hash<Emplaceable>
     52     : public std::unary_function<Emplaceable, std::size_t>
     53 {
     54     std::size_t operator()(const Emplaceable& x) const {return x.get();}
     55 };
     56 
     57 }
     58 
     59 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     60 
     61 #endif  // EMPLACEABLE_H
     62