Skip to content

Commit 9136038

Browse files
philnik777Debadri Basak
authored andcommitted
[libc++] Simplify the implementation of destroy_at a bit (llvm#165392)
1 parent ba54584 commit 9136038

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

libcxx/include/__memory/construct_at.h

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <__config>
1515
#include <__memory/addressof.h>
1616
#include <__new/placement_new_delete.h>
17-
#include <__type_traits/enable_if.h>
1817
#include <__type_traits/is_array.h>
1918
#include <__utility/declval.h>
2019
#include <__utility/forward.h>
@@ -55,35 +54,25 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __l
5554
// The internal functions are available regardless of the language version (with the exception of the `__destroy_at`
5655
// taking an array).
5756

58-
template <class _Tp, __enable_if_t<!is_array<_Tp>::value, int> = 0>
57+
template <class _Tp>
5958
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) {
6059
_LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at");
61-
__loc->~_Tp();
62-
}
63-
6460
#if _LIBCPP_STD_VER >= 20
65-
template <class _Tp, __enable_if_t<is_array<_Tp>::value, int> = 0>
66-
_LIBCPP_HIDE_FROM_ABI constexpr void __destroy_at(_Tp* __loc) {
67-
_LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at");
68-
for (auto&& __val : *__loc)
69-
std::__destroy_at(std::addressof(__val));
70-
}
61+
if constexpr (is_array_v<_Tp>) {
62+
for (auto&& __val : *__loc)
63+
std::__destroy_at(std::addressof(__val));
64+
} else
7165
#endif
66+
{
67+
__loc->~_Tp();
68+
}
69+
}
7270

7371
#if _LIBCPP_STD_VER >= 17
74-
75-
template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0>
72+
template <class _Tp>
7673
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* _LIBCPP_DIAGNOSE_NULLPTR __loc) {
7774
std::__destroy_at(__loc);
7875
}
79-
80-
# if _LIBCPP_STD_VER >= 20
81-
template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0>
82-
_LIBCPP_HIDE_FROM_ABI constexpr void destroy_at(_Tp* _LIBCPP_DIAGNOSE_NULLPTR __loc) {
83-
std::__destroy_at(__loc);
84-
}
85-
# endif
86-
8776
#endif // _LIBCPP_STD_VER >= 17
8877

8978
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)