[PATCH 2/2] libstdc++: Implement ranges [specialized.algorithms]
Jonathan Wakely
jwakely@redhat.com
Thu Feb 13 16:12:00 GMT 2020
On 12/02/20 15:41 -0500, Patrick Palka wrote:
>This implements all the ranges members defined in [specialized.algorithms]:
>
> ranges::uninitialized_default_construct
> ranges::uninitialized_value_construct
> ranges::uninitialized_copy
> ranges::uninitialized_copy_n
> ranges::uninitialized_move
> ranges::uninitialized_move_n
> ranges::uninitialized_fill
> ranges::uninitialized_fill_n
> ranges::construct_at
> ranges::destroy_at
> ranges::destroy
>
>It also implements (hopefully correctly) the "obvious" optimizations for these
>algos, namely that if the output range has a trivial value type and if the
>appropriate operation won't throw then we can dispatch to the standard ranges
>version of the algorithm which will then potentially enable further
>optimizations.
>
>libstdc++-v3/ChangeLog:
>
> * include/Makefile.am: Add <bits/ranges_uninitialized.h>.
> * include/Makefile.in: Regenerate.
> * include/bits/ranges_uninitialized.h: New header.
> * include/std/memory: Include it.
> * testsuite/20_util/specialized_algorithms/destroy/constrained.cc: New
> test.
> * .../uninitialized_copy/constrained.cc: New test.
> * .../uninitialized_default_construct/constrained.cc: New test.
> * .../uninitialized_fill/constrained.cc: New test.
> * .../uninitialized_move/constrained.cc: New test.
> * .../uninitialized_value_construct/constrained.cc: New test.
>+ template<__detail::__nothrow_input_iterator _Iter,
>+ __detail::__nothrow_sentinel<_Iter> _Sent>
>+ requires destructible<iter_value_t<_Iter>>
>+ constexpr _Iter
>+ destroy(_Iter __first, _Sent __last) noexcept
>+ {
>+ if constexpr (is_trivially_destructible_v<iter_value_t<_Iter>>)
>+ return ranges::next(__first, __last);
>+ else
>+ {
>+ for (; __first != __last; ++__first)
>+ ranges::destroy_at(addressof(*__first));
This should be std::__addressof
>+ return __first;
>+ }
>+ }
>+
>+ template<__detail::__nothrow_input_range _Range>
>+ requires destructible<range_value_t<_Range>>
>+ constexpr safe_iterator_t<_Range>
>+ destroy(_Range&& __r) noexcept
>+ { return ranges::destroy(ranges::begin(__r), ranges::end(__r)); }
>+
>+ template<__detail::__nothrow_input_iterator _Iter>
>+ requires destructible<iter_value_t<_Iter>>
>+ constexpr _Iter
>+ destroy_n(_Iter __first, iter_difference_t<_Iter> __n) noexcept
>+ {
>+ if constexpr (is_trivially_destructible_v<iter_value_t<_Iter>>)
>+ return ranges::next(__first, __n);
>+ else
>+ {
>+ for (; __n > 0; ++__first, (void)--__n)
>+ ranges::destroy_at(addressof(*__first));
Same here.
OK for master with those two adjustments.
More information about the Libstdc++
mailing list