1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Copyright 2020, Intel Corporation
//
// testing transparent
//
#ifndef LIBPMEMOBJ_CPP_TESTS_TRANSPARENT_H
#define LIBPMEMOBJ_CPP_TESTS_TRANSPARENT_H
/* Windows has a max macro which collides with std::numeric_limits::max */
#if defined(max) && defined(_WIN32)
#undef max
#endif
#include <libpmemobj++/container/string.hpp>
#include <libpmemobj++/p.hpp>
#include <limits>
#include "private_constructor.h"
#include "unittest.hpp"
struct C2Int { // comparable to int
C2Int() : i_(0)
{
}
C2Int(int i) : i_(i)
{
}
int
get() const
{
return i_;
}
private:
pmem::obj::p<int> i_;
};
bool
operator<(int rhs, const C2Int &lhs)
{
return rhs < lhs.get();
}
bool
operator<(const C2Int &rhs, const C2Int &lhs)
{
return rhs.get() < lhs.get();
}
bool
operator<(const C2Int &rhs, int lhs)
{
return rhs.get() < lhs;
}
class Moveable {
Moveable &operator=(const Moveable &);
pmem::obj::p<int> int_;
pmem::obj::p<double> double_;
public:
Moveable() : int_(0), double_(0)
{
}
Moveable(int i, double d) : int_(i), double_(d)
{
}
Moveable(Moveable &&x) : int_(x.int_), double_(x.double_)
{
x.int_ = -1;
x.double_ = -1;
}
Moveable(const Moveable &) = default;
Moveable &
operator=(Moveable &&x)
{
int_ = x.int_;
x.int_ = -1;
double_ = x.double_;
x.double_ = -1;
return *this;
}
bool
operator==(const Moveable &x) const
{
return int_ == x.int_ && double_ == x.double_;
}
bool
operator<(const Moveable &x) const
{
return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
}
int
get() const
{
return int_;
}
bool
moved() const
{
return int_ == -1;
}
};
class MoveableWrapper {
Moveable mv_;
public:
MoveableWrapper(Moveable &&mv) : mv_(std::move(mv))
{
}
Moveable
get() const
{
return mv_;
}
};
bool
operator<(const MoveableWrapper &lhs, const MoveableWrapper &rhs)
{
return lhs.get() < rhs.get();
}
bool
operator<(const MoveableWrapper &lhs, Moveable rhs)
{
return lhs.get() < rhs;
}
bool
operator<(Moveable lhs, const MoveableWrapper &rhs)
{
return lhs < rhs.get();
}
struct transparent_less {
template <class T, class U>
constexpr auto
operator()(T &&t, U &&u) const
noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
-> decltype(std::forward<T>(t) < std::forward<U>(u))
{
return std::forward<T>(t) < std::forward<U>(u);
}
using is_transparent = void; // correct
};
struct transparent_less_not_referenceable {
template <class T, class U>
constexpr auto
operator()(T &&t, U &&u) const
noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
-> decltype(std::forward<T>(t) < std::forward<U>(u))
{
return std::forward<T>(t) < std::forward<U>(u);
}
using is_transparent =
void() const &; // it's a type; a weird one, but a type
};
struct heterogenous_bytes_view {
heterogenous_bytes_view(const int *value)
{
v = (unsigned)(*value + (std::numeric_limits<int>::max)() + 1);
}
heterogenous_bytes_view(const C2Int *value)
{
v = (unsigned)(value->get() +
(std::numeric_limits<int>::max)() + 1);
}
heterogenous_bytes_view(const Moveable *value)
{
v = (unsigned)(value->get() +
(std::numeric_limits<int>::max)() + 1);
}
heterogenous_bytes_view(const MoveableWrapper *value)
{
v = (unsigned)(value->get().get() +
(std::numeric_limits<int>::max)() + 1);
}
heterogenous_bytes_view(const PrivateConstructor *value)
{
v = (unsigned)(value->get() +
(std::numeric_limits<int>::max)() + 1);
}
size_t
size() const
{
return sizeof(int);
}
char operator[](std::size_t p) const
{
return reinterpret_cast<const char *>(&v)[size() - p - 1];
}
unsigned v;
using is_transparent = void;
};
#endif // LIBPMEMOBJ_CPP_TESTS_TRANSPARENT_H
|