Date: Tue, 04 Mar 2025 17:01:29 +0200
C++ has a literal range type: std::initializer_list. However, its
elements are const and so initializing a container from the elements
involves a copy.
I propose std::ranges::literal<T>, constructed from
std::convertible_to<T>.... If all constructor parameters are rvalues,
then the range produces rvalues too.
This allows changing
auto v = std::vector<big>({big(7), big(3), big(9)});
to
auto v = std::vector<big>(std::from_range,
std::ranges::literal<big>(big(7), big(3), big(9)));
Or similarly seeding some range computation from a literal list rather
than a computed one.
elements are const and so initializing a container from the elements
involves a copy.
I propose std::ranges::literal<T>, constructed from
std::convertible_to<T>.... If all constructor parameters are rvalues,
then the range produces rvalues too.
This allows changing
auto v = std::vector<big>({big(7), big(3), big(9)});
to
auto v = std::vector<big>(std::from_range,
std::ranges::literal<big>(big(7), big(3), big(9)));
Or similarly seeding some range computation from a literal list rather
than a computed one.
Received on 2025-03-04 15:01:34