On 19.11.2019 20:48, Melzzzzz wrote:
>
> Just one question. What's the point of auto then?
It's still unclear what you're asking about. You quoted everything to be
sure not to give any indication. I snipped all that.
If you're asking about the syntax, then in C++11 the point was that
`auto` was an available keyword to use in the new syntax. The original
meaning in C, of automatic storage, was covered by that being the
default. For the new syntax, trailing return type, it was not mnemonic,
but it was deemed better than the other available keyword, `register`.
register foo() -> int
Nah.
But the committee could have chosen to use operator notation, like the
lambda notation:
[] foo() -> int
Then they'd have had a nice notation where the difference between a
named function and a basic unnamed one (lambda), would simply be that no
name was provided for the unnamed one. One conceptual problem with this
scheme is that the named functions would be declarations while the
unnamed ones would be expressions. I don't offhand see that the
possibility of `[]` occurring in a possible-declaration context would be
problematic for a compiler, e.g. leading to parse ambiguities, but maybe
it would -- the committee includes folks from compiler vendors, folks
who know a lot about the inner workings. There is however a problem of
similar notation implying similar functionality. And it doesn't make
much sense to specify captures for a named function declaration.
Alternatively the committee could have chosen to open up for new kinds
of identifiers, such as `#foo` and `$foo`, to use as new keywords (the
problems with these is that they can introduce conflicts with existing
preprocessing, in particular #foo with the *nix convention for shell
scripts). Or they could have chosen to introduce contextual keywords,
keywords that are only keywords in certain contexts, which would reduce
or eliminate breakage of existing code. Or they could have chosen to
simply add new keywords as they've now done in C++20 (there's a host of
them). Or they could go for ugliness, like `__foo`, which is safe and
readable but just ugly. They chose neither of these approaches.
I.e. they were still very very conservative for C++11, going for
technical safety instead of readability where readability mattered, and
now in C++20 for more esoteric little used features they feel more free. :(
- Alf