Emplaceable.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef EMPLACEABLE_H
  9. #define EMPLACEABLE_H
  10. #include <functional>
  11. #include "test_macros.h"
  12. #if TEST_STD_VER >= 11
  13. class Emplaceable
  14. {
  15. Emplaceable(const Emplaceable&);
  16. Emplaceable& operator=(const Emplaceable&);
  17. int int_;
  18. double double_;
  19. public:
  20. Emplaceable() : int_(0), double_(0) {}
  21. Emplaceable(int i, double d) : int_(i), double_(d) {}
  22. Emplaceable(Emplaceable&& x)
  23. : int_(x.int_), double_(x.double_)
  24. {x.int_ = 0; x.double_ = 0;}
  25. Emplaceable& operator=(Emplaceable&& x)
  26. {int_ = x.int_; x.int_ = 0;
  27. double_ = x.double_; x.double_ = 0;
  28. return *this;}
  29. bool operator==(const Emplaceable& x) const
  30. {return int_ == x.int_ && double_ == x.double_;}
  31. bool operator<(const Emplaceable& x) const
  32. {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
  33. int get() const {return int_;}
  34. };
  35. namespace std {
  36. template <>
  37. struct hash<Emplaceable>
  38. {
  39. typedef Emplaceable argument_type;
  40. typedef std::size_t result_type;
  41. std::size_t operator()(const Emplaceable& x) const {return x.get();}
  42. };
  43. }
  44. #endif // TEST_STD_VER >= 11
  45. #endif // EMPLACEABLE_H