C++ Logo

std-proposals

Advanced search

Re: Down with "template"! (up with the turbofish)

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Fri, 8 Oct 2021 15:15:48 -0500
On Fri, Oct 8, 2021 at 2:11 PM Jean-Baptiste Vallon Hoarau via
Std-Proposals <std-proposals_at_[hidden]> 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. 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.
>
> It would also not be difficult to allow the turbofish in front of every
> templates parameter list, for consistency. E;g. :
>
> ```
> template <int N> struct type{};
> type::<0> x; // not needed, but ok
> ```
>
> Would this create any conflicts with the current C++ grammar ?
>

What would you do for member function calls? For instance, today's
"x.template get<0>()" becomes... ?

Barry

Received on 2021-10-08 15:16:04