arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1306.5142cs.PL
收藏

C++中模板参数的伪运行时间选择

Fake Run-Time Selection of Template Arguments in C++

Daniel Langr, Pavel Tvrdík, Tomáš Dytrych, Jerry P. Draayer

摘要:

C++不支持模板类型参数的运行时间解析。为了规避这个限制,我们可以在编译时为所有可能的类型参数组合实例化一个模板,然后在运行时间通过评估一些提供的条件来选择合适的实例。然而,对于具有多个类型参数的模板,这样的解决方案可能容易导致分支代码膨胀。我们提出了一个模板元编程算法称为_id,允许用户选择适当的模板实例在运行时间与理论上最小的持续复杂性的分支代码。

英文摘要:

C++ does not support run-time resolution of template type arguments. To circumvent this restriction, we can instantiate a template for all possible combinations of type arguments at compile time and then select the proper instance at run time by evaluation of some provided conditions. However, for templates with multiple type parameters such a solution may easily result in a branching code bloat. We present a template metaprogramming algorithm called for_id that allows the user to select the proper template instance at run time with theoretical minimum sustained complexity of the branching code.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑