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
9#ifndef EMPLACEABLE_H
10#define EMPLACEABLE_H
11
12#include <functional>
13#include "test_macros.h"
14
15#if TEST_STD_VER >= 11
16
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 Emplaceable() : int_(0), double_(0) {}
26 TEST_CONSTEXPR Emplaceable(int i, double d) : int_(i), double_(d) {}
27 TEST_CONSTEXPR_CXX14 Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
28 x.int_ = 0;
29 x.double_ = 0;
30 }
31 TEST_CONSTEXPR_CXX14 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 bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
40 TEST_CONSTEXPR bool operator<(const Emplaceable& x) const {
41 return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
42 }
43
44 TEST_CONSTEXPR 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 std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
53};
54
55#endif // TEST_STD_VER >= 11
56#endif // EMPLACEABLE_H
57

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of libcxx/test/std/containers/Emplaceable.h