On Monday, 1 July 2024 at 11:15:46 UTC, Nick Treleaven wrote:
On Monday, 1 July 2024 at 07:32:30 UTC, Dakota wrote:
this code give error:
```d
static if( !__traits(compiles, mixin("enum v = V;")) ) {
enum v = V;
}
```
__traits(compiles, ...) can't check if a declaration is valid
directly. You have to wrap it in a function literal expression:
```d
enum isStatic(alias V) = __traits(compiles, { enum v = V; });
extern const float NotWorkVar;
const float Works = 2;
pragma(msg, isStatic!NotWorkVar); // false
pragma(msg, isStatic!Works); // true
```
Thanks, this work for me.