I wanted to archive a way to apply a function to each element of a given tuple, and I came up with a solution, which is shown in the following example.
int main()
{
std::apply([](auto&&... xs)
{
[](...){}(([](auto&& x){ std::cout << x << "\n"; }(std::forward<decltype(xs)>(xs)), false)...);
}, std::make_tuple(1, 2.f, 3.0));
}
This seems to work just fine, except that the tuple elements seem to be processed in an inverted order, which leads to the following output:
3
2
1
Can someone tell me why?
source
share