Skip to content

Commit af79957

Browse files
committed
make use of std::__construct_at
1 parent 50e5099 commit af79957

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

libcxx/include/__algorithm/stable_sort.h

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ _LIBCPP_PUSH_MACROS
3636

3737
_LIBCPP_BEGIN_NAMESPACE_STD
3838

39-
// Making placement new available in constexpr contexts. This is necessary to work around a "constexpr placement new"
40-
// bug in gcc (fixed in 14.2). See https://github.com/llvm/llvm-project/pull/110320#discussion_r1788557715.
41-
#if _LIBCPP_STD_VER >= 20
42-
# define _LIBCPP_MOVING_PLACEMENT_NEW(__ptr, __type, __move_func, __iter) std::construct_at(__ptr, __move_func(__iter))
43-
#else
44-
# define _LIBCPP_MOVING_PLACEMENT_NEW(__ptr, __type, __move_func, __iter) \
45-
::new ((void*)__ptr) __type(__move_func(__iter))
46-
#endif
47-
4839
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
4940
_LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(
5041
_BidirectionalIterator __first1,
@@ -58,22 +49,22 @@ _LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(
5849
__destruct_n __d(0);
5950
unique_ptr<value_type, __destruct_n&> __h(__first2, __d);
6051
value_type* __last2 = __first2;
61-
_LIBCPP_MOVING_PLACEMENT_NEW(__last2, value_type, _Ops::__iter_move, __first1);
52+
std::__construct_at(__last2, _Ops::__iter_move(__first1));
6253
__d.template __incr<value_type>();
6354
for (++__last2; ++__first1 != __last1; ++__last2) {
6455
value_type* __j2 = __last2;
6556
value_type* __i2 = __j2;
6657
if (__comp(*__first1, *--__i2)) {
6758
{
6859
value_type& __tmp = *__i2;
69-
_LIBCPP_MOVING_PLACEMENT_NEW(__j2, value_type, std::move, __tmp);
60+
std::__construct_at(__j2, std::move(__tmp));
7061
}
7162
__d.template __incr<value_type>();
7263
for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2)
7364
*__j2 = std::move(*__i2);
7465
*__j2 = _Ops::__iter_move(__first1);
7566
} else {
76-
_LIBCPP_MOVING_PLACEMENT_NEW(__j2, value_type, _Ops::__iter_move, __first1);
67+
std::__construct_at(__j2, _Ops::__iter_move(__first1));
7768
__d.template __incr<value_type>();
7869
}
7970
}
@@ -97,22 +88,22 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __merge_move_construct(
9788
for (; true; ++__result) {
9889
if (__first1 == __last1) {
9990
for (; __first2 != __last2; ++__first2, (void)++__result, __d.template __incr<value_type>())
100-
_LIBCPP_MOVING_PLACEMENT_NEW(__result, value_type, _Ops::__iter_move, __first2);
91+
std::__construct_at(__result, _Ops::__iter_move(__first2));
10192
__h.release();
10293
return;
10394
}
10495
if (__first2 == __last2) {
10596
for (; __first1 != __last1; ++__first1, (void)++__result, __d.template __incr<value_type>())
106-
_LIBCPP_MOVING_PLACEMENT_NEW(__result, value_type, _Ops::__iter_move, __first1);
97+
std::__construct_at(__result, _Ops::__iter_move(__first1));
10798
__h.release();
10899
return;
109100
}
110101
if (__comp(*__first2, *__first1)) {
111-
_LIBCPP_MOVING_PLACEMENT_NEW(__result, value_type, _Ops::__iter_move, __first2);
102+
std::__construct_at(__result, _Ops::__iter_move(__first2));
112103
__d.template __incr<value_type>();
113104
++__first2;
114105
} else {
115-
_LIBCPP_MOVING_PLACEMENT_NEW(__result, value_type, _Ops::__iter_move, __first1);
106+
std::__construct_at(__result, _Ops::__iter_move(__first1));
116107
__d.template __incr<value_type>();
117108
++__first1;
118109
}
@@ -170,21 +161,21 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort_move(
170161
case 0:
171162
return;
172163
case 1:
173-
_LIBCPP_MOVING_PLACEMENT_NEW(__first2, value_type, _Ops::__iter_move, __first1);
164+
std::__construct_at(__first2, _Ops::__iter_move(__first1));
174165
return;
175166
case 2:
176167
__destruct_n __d(0);
177168
unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
178169
if (__comp(*--__last1, *__first1)) {
179-
_LIBCPP_MOVING_PLACEMENT_NEW(__first2, value_type, _Ops::__iter_move, __last1);
170+
std::__construct_at(__first2, _Ops::__iter_move(__last1));
180171
__d.template __incr<value_type>();
181172
++__first2;
182-
_LIBCPP_MOVING_PLACEMENT_NEW(__first2, value_type, _Ops::__iter_move, __first1);
173+
std::__construct_at(__first2, _Ops::__iter_move(__first1));
183174
} else {
184-
_LIBCPP_MOVING_PLACEMENT_NEW(__first2, value_type, _Ops::__iter_move, __first1);
175+
std::__construct_at(__first2, _Ops::__iter_move(__first1));
185176
__d.template __incr<value_type>();
186177
++__first2;
187-
_LIBCPP_MOVING_PLACEMENT_NEW(__first2, value_type, _Ops::__iter_move, __last1);
178+
std::__construct_at(__first2, _Ops::__iter_move(__last1));
188179
}
189180
__h2.release();
190181
return;
@@ -282,7 +273,6 @@ stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
282273
std::stable_sort(__first, __last, __less<>());
283274
}
284275

285-
#undef _LIBCPP_MOVING_PLACEMENT_NEW
286276
_LIBCPP_END_NAMESPACE_STD
287277
_LIBCPP_POP_MACROS
288278

0 commit comments

Comments
 (0)