C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Named auto

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Tue, 27 Sep 2022 14:46:24 +0100
Mostly auto<T> looks weird for introducing the name T. identity<T> is not similar, since there T is just used and it's introduced elsewhere.

Also some decorated placeholders, to think what T deduces to in each of these, and if that's intuitive:
const auto<T>
auto<T> &
auto<T> &&
auto<T>*

Cheers,
Lénárd

On 27 September 2022 13:46:17 BST, Oleksandr Koval via Std-Proposals <std-proposals_at_[hidden]> wrote:
>Hi, C++20 introduced angle brackets for lambdas to simplify access to
>argument
>types. How about going further and allowing to bind type name to `auto`
>placeholder in various contexts? Motivation for it is the same as for
>having it
>for lambdas.
>For example:
>
>```cpp
>// simple variables
>auto<T> v = GetValue();
>// same as
>auto v = GetValue();
>using T = decltype(v);
>
>const auto<T>& v = GetRef();
>// same as
>const auto& v = GetRef();
>using T = std::remove_cvref_t<decltype(v)>;
>
>// parameters
>void f(auto<T> v);
>// same as
>void f(auto v){
> using T = decltype(v);
>}
>// or
>template<typename T>
>void f(T v);
>
>// structure bindings
>auto<T1, T2> [key, value] = GetPair();
>```
>
>Syntax `auto<T>` looks weird at first glance but you can think about it as
>of
>`identity<T>`. Of course this is just a sketch, maybe there's a better way
>to
>write it.
>We can also have `decltype(auto<T>)` and support parameter packs as well.
>
>--
>Regards,
>Oleksandr Koval.

Received on 2022-09-27 13:46:31