The effect of auto on compile time

后端 未结 2 1807
悲哀的现实
悲哀的现实 2021-01-04 08:07

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 quest

2条回答
  •  -上瘾入骨i
    2021-01-04 08:18

    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.

提交回复
热议问题