C++ Logo


Advanced search

Re: [std-proposals] Implicitly accepting leading default function/template argument values

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 7 Mar 2022 15:03:19 -0500
On Mon, Mar 7, 2022 at 1:07 PM Hani Deek via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> I love your proposal, because it can save tons of code. It allows us to use the brief syntax of default arguments instead of having to write multiple function overloads to supply missing argument values that are not trailing arguments.
> However, whenever you suggest something that has the effect of drastically reducing the amount of required code, people will object on the grounds that your suggestion opens the door for misinterpreting typos and unintended mistakes.
> Naturally, the less you write, the less clear your intention becomes.
> C++ generally gives favor to typo/mistake avoidance over brevity, although occasionally there were changes that violated this principle, such as the 'Down with typename' proposal of C++20. I love the fact that that proposal was adopted because it has allowed us to avoid many unnecessary uses of the 'typename' keyword, but that proposal went against the usual direction of C++.

I would say that this is a mischaracterization of both that proposal
and the general direction of C++.

`typename` was not added to the language to avoid user mistakes. It
was added as a *syntactic necessity* for compilers in certain
situations when using dependent names. Compilers have to know what
kind of thing a name is, and they cannot know that if the text leading
to said name depends on a template parameter. It can only be known
after template substitution. But C++ is not a context-free grammar;
certain aspects of the grammar depend on knowing if a name is a
variable, typename, or template. The compiler needs clarification;
hence `typename`.

The "Down with typename" proposal removed using `typename` from places
where the fact that a particular dependent name is a typename is
*known* through context. Some name `X` might be dependent and unknown,
but if it appears in `using name = X;`, there is no question that `X`
must be a typename. That's how `using` directives work. The compiler
doesn't need to be told what it is, so the proposal made it

Received on 2022-03-07 20:03:19