[libcxx-commits] [libcxx] [libc++][NFC] Simplify std::__destroy_at a bit (PR #147025)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 4 02:23:46 PDT 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/147025
None
>From 5153921b96dfac5edf5f1cdfd511ed2cbcaa879e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Fri, 4 Jul 2025 11:22:12 +0200
Subject: [PATCH] [libc++][NFC] Simplify std::__destroy_at a bit
---
libcxx/include/__memory/construct_at.h | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index 21337e766b2d0..b64e64b5a29b0 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -12,14 +12,12 @@
#include <__assert>
#include <__config>
-#include <__iterator/access.h>
#include <__memory/addressof.h>
#include <__new/placement_new_delete.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_array.h>
#include <__utility/declval.h>
#include <__utility/forward.h>
-#include <__utility/move.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -65,11 +63,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc
#if _LIBCPP_STD_VER >= 20
template <class _Tp, __enable_if_t<is_array<_Tp>::value, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) {
+_LIBCPP_HIDE_FROM_ABI constexpr void __destroy_at(_Tp* __loc) {
_LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at");
- auto const __end = std::end(*__loc);
- for (auto __it = std::begin(*__loc); __it != __end; ++__it)
- std::__destroy_at(__it);
+ for (auto&& __val : *__loc)
+ std::__destroy_at(std::addressof(__val));
}
#endif
@@ -82,7 +79,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc)
# if _LIBCPP_STD_VER >= 20
template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc) {
+_LIBCPP_HIDE_FROM_ABI constexpr void destroy_at(_Tp* __loc) {
std::__destroy_at(__loc);
}
# endif
More information about the libcxx-commits
mailing list