By declaring a static variable in a function, you
In some cases, limited volume is most important, for example. for a local constant.
In other cases, delayed dynamic initialization is most important, for example. for singleton Meyers.
( ) ,
inline
auto get_t()
-> T const&
{
static T const the_t;
return the_t;
}
T const& t = get_t();
.
++ 11 constexpr, .
, , , ( , ):
template< class Dummy >
struct The_t_constant
{
static T const value;
};
template< class Dummy >
T const The_t_constant<Dummy>::value;
T const& t = The_t_constant<void>::value;