C++ Logo

std-proposals

Advanced search

Re: [std-proposals] static static variable inside template function

From: Justin Cooke <jgc_at_[hidden]>
Date: Tue, 03 Oct 2023 19:36:58 +0200
On 3 Oct 2023 at 18:17, Frederick Virchanza Gotham via Std-Propos wrote:
>
> How about if we could specify inside a template function that a
> variable is 'static static', meaning that it's shared by all
> instantiations? So the following code:


It is unclear what you would want 'static static' to do in more complex cases.  For example, should 'static static' within a member function template of a class template mean that the variable is shared across all combinations of instantiations of the class template and of the function template, or merely that it is shared across instantiations of the function template within each given instantiation of the enclosing class template ?

It seems to me more sensible to place the static variable explicitly in the scope you want it (such as in a namespace or as a static member of a class or class template). That way you have full clarity. If you need to control the sequencing of its initialization, use the Meyers singleton idiom.


  

Received on 2023-10-03 17:37:06