summaryrefslogtreecommitdiff
path: root/libcxx/include/tuple
diff options
context:
space:
mode:
authorLouis Dionne <ldionne.2@gmail.com>2025-05-08 16:35:00 -0400
committerGitHub <noreply@github.com>2025-05-08 16:35:00 -0400
commit45d493b680e3e79e4e9c19d665df83823c52a73a (patch)
tree461ff7a2c9c3f7e4cd6ac5decfcee1f86bfc4632 /libcxx/include/tuple
parentc82e2f5c9ed08a270a1ec60bf7313af9c236ab98 (diff)
[libc++] Add the __is_replaceable type trait (#132408)
That type trait represents whether move-assigning an object is equivalent to destroying it and then move-constructing a new one from the same argument. This will be useful in a few places where we may want to destroy + construct instead of doing an assignment, in particular when implementing some container operations in terms of relocation. This is effectively adding a library emulation of P2786R12's is_replaceable trait, similarly to what we do for trivial relocation. Eventually, we can replace this library emulation by the real compiler-backed trait. This is building towards #129328.
Diffstat (limited to 'libcxx/include/tuple')
-rw-r--r--libcxx/include/tuple6
1 files changed, 4 insertions, 2 deletions
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index f6062891823d..8dd62ae624f5 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -250,6 +250,7 @@ template <class... Types>
# include <__type_traits/is_nothrow_assignable.h>
# include <__type_traits/is_nothrow_constructible.h>
# include <__type_traits/is_reference.h>
+# include <__type_traits/is_replaceable.h>
# include <__type_traits/is_same.h>
# include <__type_traits/is_swappable.h>
# include <__type_traits/is_trivially_relocatable.h>
@@ -462,8 +463,8 @@ template <class _Indx, class... _Tp>
struct __tuple_impl;
template <size_t... _Indx, class... _Tp>
-struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
- : public __tuple_leaf<_Indx, _Tp>... {
+struct _LIBCPP_DECLSPEC_EMPTY_BASES
+ __tuple_impl<__tuple_indices<_Indx...>, _Tp...> : public __tuple_leaf<_Indx, _Tp>... {
_LIBCPP_HIDE_FROM_ABI constexpr __tuple_impl() noexcept(
__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
@@ -555,6 +556,7 @@ class _LIBCPP_NO_SPECIALIZATIONS tuple {
public:
using __trivially_relocatable _LIBCPP_NODEBUG =
__conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>;
+ using __replaceable _LIBCPP_NODEBUG = __conditional_t<_And<__is_replaceable<_Tp>...>::value, tuple, void>;
// [tuple.cnstr]