Is TemplatePack<>...[I] allowed in C++26
Asked Answered
P

1

7

Pack indexing was introduced in C++26 and I was hoping for this feature to have a significant impact on metaprogramming stuff, especially for indexing packs which would otherwise require workarounds.

Since the syntax for pack indexing specifier is:

typedef-name ... [ expression ] 
  • where typedef-name is either identifier or simple-template-id

With the information above, does it allow to have like:

template <typename>
using apply_t = bool;

// #1
template <typename... Args>
using A = apply_t<Args>...[0];
// can be reworked with: apply_t<Args...[0]>

// #2
template <template <typename...> typename... Temps>
using B = Temps<>...[0]
// no other way other than this because 'Temps...[0]<>' is not allowed yet (?)
Painless answered 30/12, 2023 at 14:44 Comment(0)
P
5

No: while typedef-name includes simple-template-id as a grammar production, in this context it is required ([dcl.type.pack.index]/1) to name a pack (and Temps<> is not itself a pack).

Note that the proposal discusses indexing into template template parameter packs (and even new kinds of packs) as a future extension.

Petterson answered 30/12, 2023 at 16:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.