C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Defect report: not possible to declare-but-not-define a full specialization of a variable template

From: Avi Kivity <avi_at_[hidden]>
Date: Tue, 14 Jan 2025 06:26:49 -0500
On Mon, 2025-01-13 at 20:19 +0000, Tiago Freire wrote:
> Is there?


As I later observed, not.

> It seems to me that were it to be specialized differently in a
> different translation unit to all of a sudden do more than
> advertised, wouldn't that be an ODR violation?
>


That's a much wider problem than variable template full specialization
and any workarounds for its lack.

> -----Original Message-----
> There is a simple workaround: a static variable in a class template:
>
> template <typename T>
> struct A {
> static int var;
> };
> // A<int>::var can be referenced without the initializer being
> defined at this point
>
> template <> int A<int>::var = 7;

Received on 2025-01-14 11:26:53