On Sat, 2025-08-09 at 21:30 +0200, Jens Maurer wrote:
On 09.08.25 21:06, Avi Kivity via Std-Proposals wrote:
A modern range-based solution would look like
```c++
auto result = input
| std::views::transform([] (size_t sz) {
return std::vector<int>(sz);
}
| std::ranges::to<std::vector>();
```
This is still unsatisfying, as the lambda is not concise.
I disagree. The lambda is nice and readable.
See below.
Also, constructors in particular seem to have
std::initializer_list overloads occasionally,
but you can't perfectly-forward initializer lists.
Seems like that's a problem with initializer lists, not with the many facilities which use perfect forwarding.
Oh, and I haven't used mem_fn for ages, now that std::ranges
considers pointer-to-members invocable.
See, you prefer the conciseness. You wouldn't write a lambda to forward the call as you have an alternative.
Note, p3312 provides the ability to expose an overload set as a function object. If it's adopted, you'd write
auto result = input
| std::views::transform(&std::vector<int>::vector)
| std::ranges::to<std::vector>();
which I prefer to std::constructor.