c++parameter-packc++26

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


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 ] 

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 (?)

Solution

  • 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.