]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Replace use of __mindist in ranges::uninitialized_xxx algos [PR101587]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Mar 2025 11:47:05 +0000 (11:47 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 4 Apr 2025 11:56:59 +0000 (12:56 +0100)
commit03ac8886e5c1fa16da90276fd721a57fa9435f4f
tree1f75de5dd73ff9393f2937a7dd21b1ca54b7600d
parent84d668b0ca67c5d3fe6430f101d61e60aa796a81
libstdc++: Replace use of __mindist in ranges::uninitialized_xxx algos [PR101587]

In r15-8980-gf4b6acfc36fb1f I introduced a new function object for
finding the smaller of two distances. In bugzilla Hewill Kang pointed
out that we still need to explicitly convert the result back to the
right difference type, because the result might be an integer-like class
type that doesn't convert to an integral type explicitly.

Rather than doing that conversion in the __mindist function object, I
think it's simpler to remove it again and just do a comparison and
assignment. We always want the result to have a specific type, so we can
just check if the value of the other type is smaller, and then convert
that to the other type if so.

libstdc++-v3/ChangeLog:

PR libstdc++/101587
* include/bits/ranges_uninitialized.h (__detail::__mindist):
Remove.
(ranges::uninitialized_copy, ranges::uninitialized_copy_n)
(ranges::uninitialized_move, ranges::uninitialized_move_n): Use
comparison and assignment instead of __mindist.
* testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc:
Check with ranges that use integer-like class type for
difference type.
* testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc:
Likewise.

Reviewed-by: Tomasz Kaminski <tkaminsk@redhat.com>
Reviewed-by: Hewill Kang <hewillk@gmail.com>
libstdc++-v3/include/bits/ranges_uninitialized.h
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc