C++ 什么是MPL价值习语?

C++ 什么是MPL价值习语?,c++,templates,metaprogramming,C++,Templates,Metaprogramming,我正在浏览一篇关于生成性编程的文章,无意中发现了MPL价值习语: template <int V> class A { A(); public: static const A<V> value; }; template <int V> static const A<V> A<V>::value; 模板 甲级 { A(); 公众: 静态常数A值; }; 模板 静态常数A::值; 它是用来干什么的?我能有一个示例用例吗

我正在浏览一篇关于生成性编程的文章,无意中发现了MPL价值习语:

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

template <int V>
static const A<V> A<V>::value;
模板
甲级
{
A();
公众:
静态常数A值;
};
模板
静态常数A::值;
它是用来干什么的?我能有一个示例用例吗

从您的链接:

防止代码膨胀,只实例化需要的内容

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

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

静态常数A::值
静态
不能在此处使用。