C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Named auto

From: Oleksandr Koval <oleksandr.koval.dev_at_[hidden]>
Date: Tue, 27 Sep 2022 17:00:22 +0300
It's simple, `T` always aliases the `auto` part, not enclosing qualifiers:

pattern | type | T
const auto<T> | const char | char
auto<T> & | char& | char
auto<T> && | char&& | char
auto<T>* | char* | char

On Tue, Sep 27, 2022 at 4:46 PM Lénárd Szolnoki via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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.
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


-- 
Regards,
Oleksandr Koval.

Received on 2022-09-27 14:00:35