Quantcast
Channel: User Marco A. - Stack Overflow
Viewing all articles
Browse latest Browse all 45

Why doesn't a left fold expression invert the output of a right fold expression?

$
0
0

I'm taking a look at C++17 fold expressions and I'm wondering why does the following program outputs

4 5 6 4 5 6 

for both of the for_each calls

template<typename F, typename... T>void for_each1(F fun, T&&... args){    (fun (std::forward<T>(args)), ...);}template<typename F, typename... T>void for_each2(F fun, T&&... args){    (..., fun (std::forward<T>(args)));}int main(){     for_each1([](auto i) { std::cout << i << std::endl; }, 4, 5, 6);     std::cout << "-"<< std::endl;     for_each2([](auto i) { std::cout << i << std::endl; }, 4, 5, 6);}

Live Example

I thought that the second fold expression was meant to output the numbers in reverse order

6 5 4

How come the results are the same?


Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>