22 using namespace ::
folly;
26 struct alignas(128) BigAlign {};
27 struct HasConst final {
31 HasConst(HasConst
const&
b)
noexcept : b1(
b.b1) {}
33 HasConst& operator=(HasConst
const&) =
delete;
34 HasConst& operator=(HasConst&&) =
delete;
38 explicit HasRef(
int&
i)
noexcept(
false) : i1(
i) {}
39 HasRef(HasRef
const&
i)
noexcept(
false) : i1(
i.i1) {}
40 HasRef(HasRef&&
i)
noexcept(false) : i1(
i.i1) {}
41 HasRef& operator=(HasRef
const&) =
delete;
42 HasRef& operator=(HasRef&&) =
delete;
51 OddB(std::initializer_list<int>,
int)
noexcept(false) {}
52 explicit OddB(OddA&&) {}
53 explicit OddB(OddA
const&)
noexcept(false) {}
54 OddB(OddB&&) =
delete;
55 OddB(OddB
const&) =
delete;
56 OddB& operator=(OddB&&) =
delete;
57 OddB& operator=(OddB
const&) =
delete;
63 explicit OddA(OddB
const&) =
delete;
64 OddA(OddA&&) =
delete;
65 OddA(OddA
const&) =
delete;
66 OddA& operator=(OddA&&) =
delete;
67 OddA& operator=(OddA
const&) =
delete;
70 struct Indestructible {
71 ~Indestructible() =
delete;
97 Types<std::pair<int, long>, std::pair<OddA, OddB>, std::pair<OddB, OddA>>;
101 EXPECT_EQ(
sizeof(TypeParam),
sizeof(Replaceable<TypeParam>));
104 EXPECT_EQ(
alignof(TypeParam),
alignof(Replaceable<TypeParam>));
109 std::is_destructible<Replaceable<TypeParam>>::
value);
114 std::is_trivially_destructible<Replaceable<TypeParam>>::
value);
119 std::is_default_constructible<Replaceable<TypeParam>>::
value);
124 std::is_move_constructible<Replaceable<TypeParam>>::
value);
129 std::is_copy_constructible<Replaceable<TypeParam>>::
value);
134 std::is_move_assignable<Replaceable<TypeParam>>::
value);
139 std::is_copy_assignable<Replaceable<TypeParam>>::
value);
144 std::is_nothrow_destructible<Replaceable<TypeParam>>::
value);
149 std::is_nothrow_default_constructible<Replaceable<TypeParam>>::
value);
154 std::is_nothrow_move_constructible<Replaceable<TypeParam>>::
value);
159 std::is_nothrow_copy_constructible<Replaceable<TypeParam>>::
value);
165 std::is_nothrow_move_assignable<Replaceable<TypeParam>>::
value);
171 std::is_nothrow_copy_assignable<Replaceable<TypeParam>>::
value);
179 using T =
typename TypeParam::first_type;
180 using U =
typename TypeParam::second_type;
183 (std::is_constructible<Replaceable<T>, Replaceable<U>
const&>::
value));
186 using T =
typename TypeParam::first_type;
187 using U =
typename TypeParam::second_type;
190 (std::is_constructible<Replaceable<T>, Replaceable<U>&&>::
value));
193 using T =
typename TypeParam::first_type;
194 using U =
typename TypeParam::second_type;
198 (std::is_assignable<Replaceable<T>, Replaceable<U>
const&>::
value));
201 using T =
typename TypeParam::first_type;
202 using U =
typename TypeParam::second_type;
206 (std::is_assignable<Replaceable<T>, Replaceable<U>&&>::
value));
209 using T =
typename TypeParam::first_type;
210 using U =
typename TypeParam::second_type;
214 (std::is_nothrow_constructible<Replaceable<T>, Replaceable<U>
const&>::
218 using T =
typename TypeParam::first_type;
219 using U =
typename TypeParam::second_type;
223 (std::is_nothrow_constructible<Replaceable<T>, Replaceable<U>&&>::
value));
226 using T =
typename TypeParam::first_type;
227 using U =
typename TypeParam::second_type;
231 (std::is_nothrow_assignable<Replaceable<T>, Replaceable<U>
const&>::
235 using T =
typename TypeParam::first_type;
236 using U =
typename TypeParam::second_type;
240 (std::is_nothrow_assignable<Replaceable<T>, Replaceable<U>&&>::
value));
243 TEST(ReplaceableTest, Basics) {
244 auto rHasConstA = make_replaceable<HasConst>();
245 auto rHasConstB = make_replaceable<HasConst>(
false);
248 rHasConstA = rHasConstB;
251 rHasConstB.emplace(
true);
259 TEST(ReplaceableTest, Constructors) {
262 auto rBasicCopy1 = Replaceable<Basic>(
b);
263 auto rBasicMove1 = Replaceable<Basic>(
std::move(
b));
265 auto rBasicCopy2 = Replaceable<Basic>(rBasicCopy1);
266 auto rBasicMove2 = Replaceable<Basic>(
std::move(rBasicMove1));
271 TEST(ReplaceableTest, DestructsWhenExpected) {
274 Replaceable<HasRef> rHasRefA{
i};
275 Replaceable<HasRef> rHasRefB{
i};
287 TEST(ReplaceableTest, Conversions) {
288 Replaceable<OddB> rOddB{
in_place, {1, 2, 3}, 4};
289 Replaceable<OddA> rOddA{
std::move(rOddB)};
290 Replaceable<OddB> rOddB2{rOddA};
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
in_place_tag in_place(in_place_tag={})
requires E e noexcept(noexcept(s.error(std::move(e))))
TEST(ReplaceableTest, Basics)
constexpr auto size(C const &c) -> decltype(c.size())
::testing::Types< std::pair< int, long >, std::pair< OddA, OddB >, std::pair< OddB, OddA >> StaticAttributePairTypes
::testing::Types< char, short, int, long, float, double, char[11], Basic, BigAlign, HasConst, HasRef, OddA, OddB, Indestructible > StaticAttributeTypes
static const char *const value
#define EXPECT_TRUE(condition)
TYPED_TEST_CASE(ReplaceableStaticAttributeTest, StaticAttributeTypes)
TYPED_TEST(ReplaceableStaticAttributeTest, size)
#define EXPECT_FALSE(condition)