C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Named auto

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 18 Oct 2022 11:45:50 +0200
Hi, please not only consider, which symbols are free, but also, what is consistent with the overall language. <> is used for templates and template parameters. It parametrizes the type on the left of <>. {} is used for creating a block or for braced init lists (value, list or aggregate intialization). In the braces it specifies the values to initialize with. auto is used as a replacement for type names to indicate an unconstrained type. auto often can be replaced with a concept name to indicate a constrained type. Two type names are combined or assigned to each other with "typedef" (old-style, where one type is used like a variable name) or "using". To define a new type (name) often "class" or "typename" are used.   I think the angle brackets within lambdas since C++20 Oleksandr mentioned in the original post of this thread are more in line to template usage. They name the types only for within the lambda. And they separate the naming of new types to their usage. The suggestion was introducing auto<T> v = GetValue(); which at the same time would name T and v and intialize v with the result of GetValue() All those names would be valid for the whole block scope.   Critical points: One instruction would be a definition + initialization of variables and create names of types. Those would be valid not only for one inner block (like a function signature), but for the surrounding scope. No keyword or special easily spottable symbol would signify this compound instruction. The angle brackets would not be enough for spotting as they are used for templated types and possibly used even within this expression, e.g. vector<auto<T<U>>> x. Perhaps one can assume that auto always introduces a name? But it often does the opposite, leave out a type name. Wouldn't a separate syntax to analyze types and name types be preferable? Perhaps even as extended form of type pattern matching? Sebastian

Received on 2022-10-18 09:45:52