Cout中的C ++ 17折叠表达式 [英] C++17 fold expression in cout
本文介绍了Cout中的C ++ 17折叠表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习新的c ++ 17 fold表达式,并且从
其中 E
是 pack表达式和 I
是初始化表达式。
没有匹配您的二进制折叠(std :: cout<< args< ...)
,其形式为(I op E op .. )
。
I am learning the new c++17 fold expression and I saw this code from c++17 fold expression. I would like to know why this code work :
template<typename ...Args>
void printer(Args&&... args) {
(std::cout << ... << args) << '\n';
}
but not this one :
template<typename ...Args>
void printer(Args&&... args) {
(std::cout << args << ...) << '\n';
}
which could seems logic too and would reverse the print order in my opinion.
解决方案
As seen on cppreference, binary folds can have the following two forms:
Where E
is the pack expression and I
is the initialization expression.
There is no binary fold that matches your (std::cout << args << ...)
, which has the form of (I op E op ...)
.
这篇关于Cout中的C ++ 17折叠表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文