Date: Fri, 8 Oct 2021 23:02:12 +0300
On 10/8/21 10:10 PM, Jean-Baptiste Vallon Hoarau via Std-Proposals wrote:
> The current disambiguator for template members of context dependent
> ID is excessively verbose, to the point where members functions
> template needing explicit parameters are largely avoided. This is a
> problem.
>
> I think that the Rust "turbofish" syntax provides an elegant
> alternative, which consists of having the token "::" preceding the
> template parameters list.
> That is the code
>
> ```
> x.template get<0>();
> using f = T::template type<0>;
> ```
>
> becomes :
>
> ```
> x.get::<0>();
> using f = T::type::<0>;
> // ^^
> ```
>
> I hope that you'll agree that this syntax is more ergonomic.
Personally, I don't. To my mental code parser, this syntax makes no
sense, since the angle brackets are not connected to the template id
anymore.
> It's also
> not unpleasant from a semantic point of view, as "::" is used to query a
> child entity, and template instantiation are childs entities of the
> primary template.
No, :: is used to qualify scope, e.g. to designate members of a class or
a namespace (i.e. to specify that a given name should be looked up in
the scope of the class or namespace). An instantiation is certainly not
a member of a template and not in the scope of the template.
I'm not opposed to the idea of relaxing the need for template
disambiguator in some contexts, where a type is expected. For example,
in a using declaration, it seems there's no case where interpreting the
left angle bracket as an operator less would result in a valid code.
Note that "relaxing" means no new syntax is needed - you could simply
omit the disambiguator.
> The current disambiguator for template members of context dependent
> ID is excessively verbose, to the point where members functions
> template needing explicit parameters are largely avoided. This is a
> problem.
>
> I think that the Rust "turbofish" syntax provides an elegant
> alternative, which consists of having the token "::" preceding the
> template parameters list.
> That is the code
>
> ```
> x.template get<0>();
> using f = T::template type<0>;
> ```
>
> becomes :
>
> ```
> x.get::<0>();
> using f = T::type::<0>;
> // ^^
> ```
>
> I hope that you'll agree that this syntax is more ergonomic.
Personally, I don't. To my mental code parser, this syntax makes no
sense, since the angle brackets are not connected to the template id
anymore.
> It's also
> not unpleasant from a semantic point of view, as "::" is used to query a
> child entity, and template instantiation are childs entities of the
> primary template.
No, :: is used to qualify scope, e.g. to designate members of a class or
a namespace (i.e. to specify that a given name should be looked up in
the scope of the class or namespace). An instantiation is certainly not
a member of a template and not in the scope of the template.
I'm not opposed to the idea of relaxing the need for template
disambiguator in some contexts, where a type is expected. For example,
in a using declaration, it seems there's no case where interpreting the
left angle bracket as an operator less would result in a valid code.
Note that "relaxing" means no new syntax is needed - you could simply
omit the disambiguator.
Received on 2021-10-08 15:02:17