C++26 中是否允许 TemplatePack<>...[I]

Des*_*old 6 c++ parameter-pack c++26

包索引是在 C++26 中引入的,我希望此功能能够对元编程产生重大影响,特别是对于索引包,否则需要解决方法。

由于包索引说明符的语法是:

typedef-name ... [ expression ] 
Run Code Online (Sandbox Code Playgroud)
  • 其中typedef-nameidentifiersimple-template-id

有了上述信息,是否允许:

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 (?)
Run Code Online (Sandbox Code Playgroud)

Dav*_*ing 5

:虽然typedef-name包含simple-template-id作为语法产生式,但在这种情况下,需要 ([dcl.type.pack.index]/1) 来命名包(并且Temps<>本身不是包)。

请注意,该提案讨论了模板参数包(甚至新类型的包)的索引作为未来的扩展。