[英]Reduce << operator chain in std::cout
Is there any way to reduce the chain of <<
operator from the statements like following ?有什么方法可以从如下语句中减少<<
运算符的链?
std::cout << var1 << "!=" << var2;
printf()
may be an option but anything else? printf()
可能是一种选择,但还有其他选择吗?
Because as the number of the operator <<
increases so the running time too.因为随着操作符<<
数量增加,运行时间也会增加。
Is it possible to efficiently reduce the <<
chain ?是否可以有效地减少<<
链?
No, this is not possible.不,这是不可能的。
The fundamental reason is that operator<<(const char*)
and operator<<(int)
are both simple.根本原因是operator<<(const char*)
和operator<<(int)
都很简单。 In fact, they're so simple that they're likely to be inlined.事实上,它们是如此简单以至于它们很可能被内联。
printf(const char* format, ...)
on the other hand is a very complex function as it needs to deal with many possible format specifiers, and it also has a variable argument list that it needs to parse. printf(const char* format, ...)
另一方面是一个非常复杂的函数,因为它需要处理许多可能的格式说明符,并且它还有一个需要解析的变量参数列表。
Any other single function would have the same disadvantage of being so complex it can't be inlined.任何其他单个函数都具有相同的缺点,即过于复杂以至于无法内联。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.