c++ - Are static variables inlined by default inside templates in C++17? -
are static variables inlined default inside templates in c++17? here's example:
template<typename t> struct someclass { static t test; }; struct someclass2 { static constexpr int test = 9; };
are variables inlined or still need out of line definition odr used?
a static constexpr
implicitly inline
, otherwise need mark inline
template<typename t> struct someclass { inline static t test; // inline }; struct someclass2 { static constexpr int test = 9; // inline };
cfr. n4606 [depr.static_constexpr]
for compatibility prior c++ international standards, constexpr static data member may redundantly redeclared outside class no initializer. usage deprecated.
example:
struct { static constexpr int n = 5; // definition (declaration in c++ 2014) }; const int a::n; // redundant declaration (definition in c++ 2014)
and [dcl.constexpr]
(barry beat me it)
a function or static data member declared constexpr specifier implicitly inline function or variable (7.1.6).
Comments
Post a Comment