for (int i = 0; i < 5; ++i) {
std::get<i>(tuple);
}
this doesn't compile, since i
is not a compile time constant. On How can you iterate over the elements of an std::tuple? and other posts I see answers of recursion, or using std::apply
, but those lose the index control. I also don't want to limit myself soley on std::tuple
.
Whenever I have to loop over something at compile time I have to stop and think and do weird things especially when I try to achieve non-standard iterations like reverse, custom increment, or involve multiple indices in the same statements such as std::get<i>(tuple) * std::get<i + 1>(tuple)
.
with c++20 what is the closest we can have to a constexpr for (int i = 0; i < 5; ++i)
?