3 ms·
Reading the example: template <typename... T> constexpr auto first_plus_last(T... values) -> T...[0] { return T...[0](values...[0] + values...[
by munch117 2y ago
Reading the example:
template <typename... T>
constexpr auto first_plus_last(T... values) -> T...[0] {
return T...[0](values...[0] + values...[sizeof...(values)-1]);
}
it seems there are 5 different kinds of uses of "...".
1. typename...
2. sizeof...
3. values...
4. T... representing multiple parameters in the formal parameter list.
5. T... for the type of the pack (supporting T...[0], the new feature).
I don't have a big point, I'm just mildly amused. Even with the simplifying new syntax, it took me a while to work through what is what in the example.
I wonder why it's T...[0] and not just T[0]? In parameter lists you need the distinction between "T", a single parameter of pack type, and "T...", multiple parameters supplied from the pack. But I don't see a similar need in an expression.
- gpderetta 2y agoI think for types you could do without the dots in T...[0], but it mirrors the usage for values (values...[0] is different from (values[0]...). So consistency I guess.