gpt4 book ai didi

c++ - 什么是 MPL 值习语?

转载 作者:行者123 更新时间:2023-11-28 06:52:58 25 4
gpt4 key购买 nike

我正在浏览 tutorial关于生成式编程,我偶然发现了MPL-value idiom:

template <int V>
class A
{
A();
public:
static const A<V> value;
};

template <int V>
static const A<V> A<V>::value;

它有什么用?我可以举个例子吗?

最佳答案

来自您的链接:

Preventing code bloat, only instantiate what is needed.

在幻灯片 35 上,演示者给出了一个示例,其中成语中的 A 类对应于 Reportable 类。

通过这个习惯用法,他实现了只实例化需要的类。比较他之前的示例(幻灯片 32),在该示例中他必须定义类的对象,无论是否使用它。模板化版本不会发生这种情况。

关于c++ - 什么是 MPL 值习语?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23558453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com