brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · d8d3407 Raw
57 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef EMPLACEABLE_H10#define EMPLACEABLE_H11 12#include <functional>13#include "test_macros.h"14 15#if TEST_STD_VER >= 1116 17class Emplaceable {18  TEST_CONSTEXPR Emplaceable(const Emplaceable&);19  TEST_CONSTEXPR_CXX14 Emplaceable& operator=(const Emplaceable&);20 21  int int_;22  double double_;23 24public:25  TEST_CONSTEXPR_CXX20 Emplaceable() : int_(0), double_(0) {}26  TEST_CONSTEXPR_CXX20 Emplaceable(int i, double d) : int_(i), double_(d) {}27  TEST_CONSTEXPR_CXX20 Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {28    x.int_    = 0;29    x.double_ = 0;30  }31  TEST_CONSTEXPR_CXX20 Emplaceable& operator=(Emplaceable&& x) {32    int_      = x.int_;33    x.int_    = 0;34    double_   = x.double_;35    x.double_ = 0;36    return *this;37  }38 39  TEST_CONSTEXPR_CXX20 bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }40  TEST_CONSTEXPR_CXX20 bool operator<(const Emplaceable& x) const {41    return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);42  }43 44  TEST_CONSTEXPR_CXX20 int get() const { return int_; }45};46 47template <>48struct std::hash<Emplaceable> {49  typedef Emplaceable argument_type;50  typedef std::size_t result_type;51 52  TEST_CONSTEXPR_CXX20 std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }53};54 55#endif // TEST_STD_VER >= 1156#endif // EMPLACEABLE_H57