问题描述
我们在C ++ 11中得到的新的auto关键字对我来说看起来很模板化,所以我的问题是 - 它会引起与模板一样的编译时间膨胀吗?
关于多态lambdas的同样的问题:
[](auto val){...}
这本质上是一个模板lambda - 这会影响编译时间吗?
C ++ 11的
auto
关键字远比模板重量轻 - 它的编译时间开销与 sizeof
相当,这意味着它接近于零。 与编译器需要的模板为了在扩展期间执行大量的计算(C ++中的模板语言是Turing-complete), auto
关键字要求编译器找出一个表达式的类型是编译器知道的东西。事实上,即使没有 auto
关键字来决定是否需要应用类型转换,它也必须找出表达式的类型。
The new auto keyword that we got in C++11 looks quite templat'ish to me so my question is - will it incur the same compile time bloat as templates do?
The same question in regards to polymorphic lambdas:
[](auto val) {...}
this is essentially a template lambda - will this impact compile time or not?
The auto
keyword of C++11 is far less heavyweight than templates - its compile-time "overhead" is comparable to that of sizeof
, which means it's close to zero.
Unlike templates where the compiler needs to perform sizeable amount of computation during the expansion (the template language in C++ is Turing-complete), the auto
keyword requires the compiler to figure out the type of an expression, which is something the compiler knows anyway. In fact, it would have to figure out the type of the expression even without the auto
keyword to decide if type conversions need to be applied.
这篇关于auto对编译时间的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!