[libcxx-commits] [libcxx] [libc++][NFC] Simplify std::__destroy_at a bit (PR #147025)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 8 19:28:52 PDT 2025


================
@@ -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));
----------------
frederick-vs-ja wrote:

No change requested. I still _think_ we should destroy array elements in reversed order. [LWG3889](https://cplusplus.github.io/LWG/issue3889) was submitted for this. But that's not related to this PR yet.

https://github.com/llvm/llvm-project/pull/147025


More information about the libcxx-commits mailing list