考慮下面的代碼: template<typename T>
constexpr inline T fma(T a, T b, T c)
{
return a * b + c;
}
這編譯就好了。但爲什麼呢?理論上,constexpr函數只能調用其他constexpr函數。但是,不能保證運營商將具有協同功能。舉例來說,假設我有一些類型有以下接口: 運算符+和* 不 constex
我想知道如何初始化一個數組,其中的值可以在常量表達式中使用。 這裏是我的問題的解釋: // The goal : initializing an array for a class
// whose values can be used as normal static const
// (as template parameters for example)
class MyClass