Skip to content

Commit df80f76

Browse files
align is_replaceable with p2786 semantics and allow user opt-in
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
1 parent a5585d2 commit df80f76

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,36 @@
1414

1515
namespace hpx::experimental {
1616

17-
HPX_CXX_EXPORT template <typename T>
17+
#if defined(__cpp_lib_trivially_relocatable)
18+
HPX_CXX_CORE_EXPORT template <typename T>
19+
struct is_replaceable : std::is_replaceable<T>
20+
{
21+
};
22+
#else
23+
HPX_CXX_CORE_EXPORT template <typename T>
1824
struct is_replaceable
19-
: std::bool_constant<std::is_move_constructible_v<T> &&
20-
std::is_move_assignable_v<T> && is_trivially_relocatable_v<T>>
25+
: std::bool_constant<std::is_object_v<T> && !std::is_const_v<T> &&
26+
!std::is_volatile_v<T> &&
27+
(std::is_scalar_v<T> ||
28+
((std::is_class_v<T> || std::is_union_v<T>) &&
29+
std::is_trivially_move_constructible_v<T> &&
30+
std::is_trivially_move_assignable_v<T> &&
31+
std::is_trivially_destructible_v<T>) )>
32+
{
33+
};
34+
35+
HPX_CXX_CORE_EXPORT template <typename T>
36+
struct is_replaceable<T[]> : std::false_type
37+
{
38+
};
39+
40+
HPX_CXX_CORE_EXPORT template <typename T, std::size_t N>
41+
struct is_replaceable<T[N]> : std::false_type
2142
{
2243
};
44+
#endif
2345

24-
HPX_CXX_EXPORT template <typename T>
46+
HPX_CXX_CORE_EXPORT template <typename T>
2547
inline constexpr bool is_replaceable_v = is_replaceable<T>::value;
2648

2749
} // namespace hpx::experimental

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ static_assert(!is_replaceable_v<void>);
4242
// std::mutex is not move assignable, nor trivially relocatable
4343
static_assert(!is_replaceable_v<std::mutex>);
4444

45+
struct trivial_class
46+
{
47+
int x;
48+
};
49+
static_assert(is_replaceable_v<trivial_class>);
50+
4551
struct not_destructible
4652
{
47-
not_destructible(not_destructible const&);
4853
not_destructible(not_destructible&&);
4954
~not_destructible() = delete;
5055
};
@@ -63,15 +68,16 @@ struct not_move_constructible
6368
};
6469
static_assert(!is_replaceable_v<not_move_constructible>);
6570

66-
struct move_assignable_but_not_trivially_relocatable
71+
struct move_assignable_but_not_implicitly_replaceable
6772
{
6873
std::unique_ptr<int> p;
69-
move_assignable_but_not_trivially_relocatable(
70-
move_assignable_but_not_trivially_relocatable&&) = default;
71-
move_assignable_but_not_trivially_relocatable& operator=(
72-
move_assignable_but_not_trivially_relocatable&&) = default;
74+
move_assignable_but_not_implicitly_replaceable(
75+
move_assignable_but_not_implicitly_replaceable&&) = default;
76+
move_assignable_but_not_implicitly_replaceable& operator=(
77+
move_assignable_but_not_implicitly_replaceable&&) = default;
7378
};
74-
static_assert(!is_replaceable_v<move_assignable_but_not_trivially_relocatable>);
79+
static_assert(
80+
!is_replaceable_v<move_assignable_but_not_implicitly_replaceable>);
7581

7682
// Opt-in example
7783
struct opt_in_replaceable

0 commit comments

Comments
 (0)