Skip to content

Commit d9bd2e9

Browse files
committed
move-explicitly
1 parent a318f8d commit d9bd2e9

File tree

1 file changed

+11
-33
lines changed

1 file changed

+11
-33
lines changed

libcxx/include/__algorithm/radix_sort.h

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
// - if all values of a radix are the same, we do not sort that radix, and just move items to the buffer;
2828
// - if two consecutive radices satisfies condition above, we do nothing for these two radices.
2929

30-
#include <__algorithm/copy.h>
3130
#include <__algorithm/for_each.h>
31+
#include <__algorithm/move.h>
3232
#include <__bit/countl.h>
3333
#include <__config>
3434
#include <__functional/identity.h>
@@ -65,16 +65,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6565

6666
#if _LIBCPP_STD_VER >= 14
6767

68-
template <class _Iterator, enable_if_t<is_move_assignable<__iter_value_type<_Iterator>>::value, int> = 0>
69-
_LIBCPP_HIDE_FROM_ABI constexpr move_iterator<_Iterator> __move_assign_please(_Iterator __i) {
70-
return std::make_move_iterator(std::move(__i));
71-
}
72-
73-
template <class _Iterator, enable_if_t<!is_move_assignable<__iter_value_type<_Iterator>>::value, int> = 0>
74-
_LIBCPP_HIDE_FROM_ABI constexpr _Iterator __move_assign_please(_Iterator __i) {
75-
return __i;
76-
}
77-
7868
template <class _UnsignedInteger>
7969
_LIBCPP_HIDE_FROM_ABI constexpr _UnsignedInteger __intlog2(_UnsignedInteger __n) {
8070
static_assert(is_unsigned<_UnsignedInteger>::value, "Must be unsigned integral");
@@ -153,7 +143,7 @@ __dispose(_ForwardIterator __first,
153143
_RandomAccessIterator2 __counters) {
154144
std::for_each(__first, __last, [&__result, &__counters, &__map](auto&& __preimage) {
155145
auto __index = __counters[__map(__preimage)]++;
156-
__result[__index] = std::forward<decltype(__preimage)>(__preimage);
146+
__result[__index] = std::move(__preimage);
157147
});
158148
}
159149

@@ -217,7 +207,7 @@ _LIBCPP_HIDE_FROM_ABI void __dispose_backward(
217207
std::make_reverse_iterator(__first),
218208
[&__result, &__counters, &__map](auto&& __preimage) {
219209
auto __index = --__counters[__map(__preimage)];
220-
__result[__index] = std::forward<decltype(__preimage)>(__preimage);
210+
__result[__index] = std::move(__preimage);
221211
});
222212
}
223213

@@ -247,13 +237,11 @@ _LIBCPP_HIDE_FROM_ABI void __radix_sort_impl(
247237
_RandomAccessIterator2 __buffer,
248238
_Map __map,
249239
_Radix __radix) {
250-
auto __buffer_end = std::__counting_sort_impl(
251-
std::__move_assign_please(__first),
252-
std::__move_assign_please(__last),
253-
__buffer,
254-
[&__map, &__radix](const auto& value) { return __radix(__map(value)); });
240+
auto __buffer_end = std::__counting_sort_impl(__first, __last, __buffer, [&__map, &__radix](const auto& value) {
241+
return __radix(__map(value));
242+
});
255243

256-
std::copy(std::__move_assign_please(__buffer), std::__move_assign_please(__buffer_end), __first);
244+
std::move(__buffer, __buffer_end, __first);
257245
}
258246

259247
template <
@@ -287,31 +275,21 @@ _LIBCPP_HIDE_FROM_ABI void __radix_sort_impl(
287275
}
288276

289277
if (__n0th_is_single) {
290-
std::copy(std::__move_assign_please(__first), std::__move_assign_please(__last), __buffer_begin);
278+
std::move(__first, __last, __buffer_begin);
291279
} else {
292280
auto __n0th = [__radix_number, &__map, &__radix](const auto& __v) {
293281
return std::__nth_radix(__radix_number, __radix, __map(__v));
294282
};
295-
std::__dispose_backward(
296-
std::__move_assign_please(__first),
297-
std::__move_assign_please(__last),
298-
__buffer_begin,
299-
__n0th,
300-
__counters[__radix_number]);
283+
std::__dispose_backward(__first, __last, __buffer_begin, __n0th, __counters[__radix_number]);
301284
}
302285

303286
if (__n1th_is_single) {
304-
std::copy(std::__move_assign_please(__buffer_begin), std::__move_assign_please(__buffer_end), __first);
287+
std::move(__buffer_begin, __buffer_end, __first);
305288
} else {
306289
auto __n1th = [__radix_number, &__map, &__radix](const auto& __v) {
307290
return std::__nth_radix(__radix_number + 1, __radix, __map(__v));
308291
};
309-
std::__dispose_backward(
310-
std::__move_assign_please(__buffer_begin),
311-
std::__move_assign_please(__buffer_end),
312-
__first,
313-
__n1th,
314-
__counters[__radix_number + 1]);
292+
std::__dispose_backward(__buffer_begin, __buffer_end, __first, __n1th, __counters[__radix_number + 1]);
315293
}
316294
}
317295
}

0 commit comments

Comments
 (0)