C++ Logo

std-proposals

Advanced search

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

From: Jean-Baptiste Vallon Hoarau <jeanbaptiste.vallon_at_[hidden]>
Date: Fri, 8 Oct 2021 21:10:14 +0200
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 ?

Received on 2021-10-08 14:10:27