是否有用于模板使用的优化 C++ 编译器?

2022-01-17 00:00:00 templates compiler-construction c++

C++ 模板因其强大的功能而成为我日常工作中的福音.但是不能忽略大量使用模板(hello 元编程和 Boost 库)导致的(非常非常非常长的)编译时间.我已经阅读并尝试了很多手动重组和修改模板代码以使其尽快编译的可能性.

C++ templates have been a blessing in my everyday work because of its power. But one cannot ignore the (very very very very long) compilation time that results from the heavy use of templates (hello meta-programming and Boost libraries). I have read and tried quite a lot of possibilities to manually reorganize and modify template code to make it compile as fast as possible.

现在我想知道是否有任何 c++ 编译器尝试最小化解释模板类所需的时间.我可能错了,但我觉得我所知道的编译器只是在他们以前的版本中添加了模板解释.

Now I am wondering if there are any c++ compilers that try and minimize the needed time to interpret template classes. I might be wrong, but i feel that the compilers i do know have only added template interpretation to their previous versions.

我的问题是:

  • c++ 模板代码是不是很难解释,没有太多需要优化的地方?(我非常怀疑)
  • 是否有真正优化c++ 模板"解释的 c++ 编译器?
  • 是否有开发新一代 c++ 编译器的项目可以对此进行优化?
  • 如果您要参与这样的项目,您的指导方针是什么?

推荐答案

g++ 4.5 似乎在模板处理方面取得了巨大的进步.这是两个不可避免的变化.

It seems that g++ 4.5 has made tremendous progress dealing with templates. Here are the two unavoidable changes.

  • 当打印类模板特化的名称时,G++ 现在将省略任何来自默认模板参数的模板参数."这可以被认为是一个微妙的修改,但它会对使用 c++ 模板的开发产生巨大的影响(听说过不可读的错误消息......?不再有!)

  • "When printing the name of a class template specialization, G++ will now omit any template arguments which come from default template arguments." That could be considered a subtle modification, but it will have an enormous impact on development with c++ templates (ever heard of unreadable error messages... ? No more !)

使用模板的代码的编译时间现在应该随着实例化的数量而线性缩放,而不是二次缩放."这将严重破坏反对使用 C++ 模板的编译时参数.

"Compilation time for code that uses templates should now scale linearly with the number of instantiations rather than quadratically." This is going to severely undermine compilation-time arguments against the use of C++ templates.

有关完整信息,请参阅 gnu 站点

See on the gnu site for complete information

实际上,我已经想知道 C++ 模板是否还有问题!嗯,是的,有,但现在让我们专注于光明的一面!

Actually, i am already wondering whether there still are issues with c++ templates ! Mmm, yes, there are, but let's focus on the bright side for now !

相关文章