C++26: pack indexing -- Sandor Dargo

SANDOR_DARGO_ROUND.JPGC++26 introduces pack indexing as a core language feature, making it significantly easier to extract specific elements from parameter packs using a familiar subscript syntax. This improvement, proposed by Corentin Jabot and Pablo Halpern, eliminates the need for cumbersome workarounds like recursive templates or boolean expression tricks, providing a more intuitive and readable approach.

C++26: pack indexing

by Sandor Dargo

From the article:

C++11 introduced parameter packs to provide a safer way to pass an undefined number of parameters to functions instead of relying on variadic functions.

While packs are a useful feature, and since C++17 it’s so easy to use them in fold expressions, extracting a specific element of a pack is somewhat cumbersome.

You either have to rely on some standard functions not made for the purpose or use “awkward boolean expression crafting or recursive templates”. None of them is unbearable, but it might be error-prone or simply expensive regarding compile-time performance. Nevertheless, they are not the most readable solutions.

C++26 brings us pack indexing as a core language feature thanks to the proposal of Corentin Jabot and Pablo Halpern, P2662R3.

Before discussing some interesting points, first, let’s look at an example:

packindexing-dargo.png

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.