Skip to content

Conversation

@guptapratykshh
Copy link
Contributor

Fixes #6625

Proposed Changes

  • added is_replaceable trait to align with p2786r13
  • updated is_trivially_relocatable to use the standard version if the c++26 feature macro is present
  • wired up relocate_at to call std::relocate_at when available

Any background context you want to provide?

Checklist

Not all points below apply to all pull requests.

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

@StellarBot
Copy link

Can one of the admins verify this patch?

@hkaiser
Copy link
Member

hkaiser commented Feb 2, 2026

@isidorostsa Would you please have a look?

Copy link
Contributor

@isidorostsa isidorostsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @guptapratykshh thank you for taking a look at this!

Unfortunately, P2786 was pulled last minute from C++26 in the Kona meeting, so the issue you tackled is outdated, I apologize for that.

That being said, it wouldn't hurt to implement the replaceable trait.

Great code!


#if defined(__cpp_lib_trivially_relocatable)
template <typename T>
struct is_trivially_relocatable : std::is_trivially_relocatable<T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also be added to the replacabillity definition

// noexcept if the memmove path is taken or if the move path is noexcept
noexcept(detail::relocate_at_helper(src, dst)))
{
#if defined(__cpp_lib_trivially_relocatable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think std::relocate_at is being proposed, but I'm not sure.

If it is, it would be better to avoid defining all the helpers and replace everything with a using relocate_at.

namespace hpx::experimental {

HPX_CXX_EXPORT template <typename T>
struct is_replaceable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A type is replaceable if what you get from move constructing is the same you get from move assigning.
In code:

T move_assigned = some_t();

T move_constructed(std::move(existing));    // 1
move_assigned = std::move(existing);        // 2

You want move_constructed to be the same as move_assigned, and the conditions you've put forth are not enough to understand if this is true.

Replaceable is an opt-in trait, you might want to take a look at how we deal with such traits in the is_trivially_relocatable definition.

Take a look at this paper to learn more about how to detect replaceability.

@@ -0,0 +1,71 @@
// Copyright (c) 2025 Isidoros Tsaousis-Seiras
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should replace this with your own copyright here

#include <mutex>
#include <type_traits>

using hpx::experimental::is_replaceable_v;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those tests should be updated in accordance with the changes in the implementation of the replacabillity trait.

Signed-off-by: guptapratykshh <[email protected]>
Copy link
Contributor

@isidorostsa isidorostsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this checking for trivial relocatabillity?
How would a user opt in?

I suggest reviewing P2786 to get a tighter grip on the specifics of this type trait.

Thanks!

@guptapratykshh
Copy link
Contributor Author

thanks for the feedback. i have updated is_replaceable to strictly follow p2786r13, remove the trivial relocatability check, and allow users to opt in via specialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update relocation semantics to match P2786R13

4 participants