Pack Indexing and Constexpr Indices #519
Unanswered
WotJProject
asked this question in
Q&A
Replies: 1 comment 5 replies
-
|
Because there's a major difference. Your parameter packs are not forced to be homogeneous, the types can differ from one parameter to the next. Putting them in an array forces them to all be the same type, and could also confuse the optimizer into including unused values in the final generated binary depending on how well it can see through what you're doing. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been exploring pack indexing in C++26, and was curious about why the index must be a constant expression (not even a
constvalue is accepted). If you write a variadic/recursive statement, load the pack into an array, or otherwise use a more verbose (and possibly expensive) workaround, you can get the exact same functionality. Parameter packs are just that- parameters, so why can't we access members of the pack more easily?EDIT: Added a fourth method I figured out. Might be the best way to deal with non-trivial types without too much overhead or if variadic recursion is undesired.
Here's some example code of variadic addition functions:
if constexprto estimate the typical size, only using a buffer for larger packs.(tested with GCC (trunk), in both -O0 and -O3.)
Beta Was this translation helpful? Give feedback.
All reactions