I have a workaround for this. It probably looks ugly, but fixes some of my problems.
First, I define a type with zero size:
typedef int zero[0];
Next, I create a macro:
#ifndef VAR #define VAR(Enable,YourType,VarName) \ std::conditional< Enable,YourType,zero >::type VarName #endif
Then a class like this:
template < int Cond > class Foo { VAR(Cond == 0,int,var); void print() { if (!sizeof(var)) return;
When you use a var type result, check its size before using it. If the size is zero, it is invalid.
source share