Fold expressions seem to be a nice way to apply a function to each element of a tuple. However, if the applied function has side effects, the order of function invocations might be an important concern.
Consider:
#include <iostream>
template<typename... Ts>
void printStuff(Ts... args)
{
( ([](auto&& v) { std::cout << v << " "; })(args), ... );
std::cout << '\n';
}
int main()
{
printStuff("hello", 42, 1.5f);
// expected output: hello 42 1.5
}
This seems to work.
But is the order of evaluation for the lambdas guaranteed here or could I end up with the values being flipped around in the output? Does the answer change if I used a different operator for chaining the commands together?