C++ Logo


Advanced search

Re: [std-proposals] Named auto

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 27 Sep 2022 10:02:14 -0400
On Tue, Sep 27, 2022 at 8:46 AM Oleksandr Koval via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Hi, C++20 introduced angle brackets for lambdas to simplify access to argument
> types.

That's not why it was done. It was done so that you could do things like this:

[]<typename T>(vector<T> const& x) {}

Here, you're defining a lambda that can take a `vector` over any
value-type (with a standard allocator) using template argument
deduction. You couldn't do that before; you would have had to either
accept any type and fail if the user provided the wrong type, or you
could accept `vector`s over a specific `T`.

Now, you can certainly use it to get the name for a template
parameters type, but that's not the primary reason this feature

Overall, what you're proposing is a convenience feature, but it's not
really all that necessary most of the time. Users already have the
tools to assign a name for an auto-deduced variable's type if they
need one. It may take a bit more text to do so, but that's not
particularly onerous, especially considering how often it is actually

Received on 2022-09-27 14:03:24