libstdc++: Implement LWG 4016 for std::ranges::to
commit45630fbcf7875b5e78c74ff4fb35cc09cd2e4e9b
authorJonathan Wakely <jwakely@redhat.com>
Sun, 26 Nov 2023 21:32:35 +0000 (26 21:32 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 5 Dec 2023 23:34:12 +0000 (5 23:34 +0000)
tree146f8e00c9f8cc73f8a8c2db4c01fcf2767f7241
parent5e8a30d8b8f4d7ea0a8340b46c1e0c865dbde781
libstdc++: Implement LWG 4016 for std::ranges::to

This implements the proposed resolution of LWG 4016, so that
std::ranges::to does not use std::back_inserter and std::inserter.
Instead it inserts at the back of the container directly, using
the first supported one of emplace_back, push_back, emplace, and insert.

Using emplace avoids creating a temporary that has to be moved into the
container, for cases where the source range and the destination
container do not have the same value type.

libstdc++-v3/ChangeLog:

* include/std/ranges (__detail::__container_insertable): Remove.
(__detail::__container_inserter): Remove.
(ranges::to): Use emplace_back or emplace, as per LWG 4016.
* testsuite/std/ranges/conv/1.cc (Cont4, test_2_1_4): Check for
use of emplace_back and emplace.
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/conv/1.cc