Skip to content

Commit 37063e4

Browse files
address maintainer feedback on is_replaceable semantics and tests
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
1 parent df80f76 commit 37063e4

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

libs/core/type_support/include/hpx/type_support/is_replaceable.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
#include <hpx/config.hpp>
1010

11+
#include <cstddef>
1112
#include <type_traits>
1213

1314
#include <hpx/type_support/is_trivially_relocatable.hpp>
1415

1516
namespace hpx::experimental {
1617

17-
#if defined(__cpp_lib_trivially_relocatable)
18+
#if defined(__cpp_lib_is_replaceable)
1819
HPX_CXX_CORE_EXPORT template <typename T>
1920
struct is_replaceable : std::is_replaceable<T>
2021
{

libs/core/type_support/tests/unit/is_replaceable.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2025 Pratyksh Gupta
1+
// Copyright (c) 2026 Pratyksh Gupta
22
//
33
// SPDX-License-Identifier: BSL-1.0
44
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -19,11 +19,14 @@ static_assert(is_replaceable_v<int>);
1919
// Const types are not assignable (thus not replaceable)
2020
static_assert(!is_replaceable_v<int const>);
2121

22-
// Pointer types are replaceable
22+
// Pointer types are replaceable if they are not const-qualified themselves.
2323
static_assert(is_replaceable_v<int*>);
24-
static_assert(is_replaceable_v<int const*>); // pointer itself is mutable
25-
static_assert(
26-
!is_replaceable_v<int* const>); // const pointer is not replaceable
24+
static_assert(is_replaceable_v<int const*>);
25+
26+
// Pointers follow the same rules as other objects. A pointer is replaceable only
27+
// if it is not const-qualified itself, as replacement requires assignment.
28+
// P2786R13 Section 3.2: "const-qualified objects are never replaceable."
29+
static_assert(!is_replaceable_v<int* const>);
2730

2831
// Function pointers are replaceable
2932
static_assert(is_replaceable_v<int (*)()>);
@@ -48,6 +51,10 @@ struct trivial_class
4851
};
4952
static_assert(is_replaceable_v<trivial_class>);
5053

54+
// Replaceability implies a type can be destroyed and reconstructed.
55+
// Consequently, a type must be destructible to be replaceable.
56+
// Per P2786R13, implicit replaceability also requires trivial relocatability,
57+
// which in turn requires trivial destructibility.
5158
struct not_destructible
5259
{
5360
not_destructible(not_destructible&&);

0 commit comments

Comments
 (0)