On Mon, Mar 01, 2021 at 08:05:57PM +, Jack via Digitalmars-d-learn wrote:
> bool g(T)(T)
> {
> return __traits(compiles, mixin("{ enum a = t; }"));
> }
>
>
> int a;
> enum s = "";
> // both return false but g(s) is expected to return true
> pragma(msg, g(s));
> pragma(msg, g(a));
On Monday, 1 March 2021 at 20:05:57 UTC, Jack wrote:
int a;
enum s = "";
// both return false but g(s) is expected to return true
So the value must be known at compile time without any extra
context. So that `a` variable might be changed somewhere else so
compile time can't read or write it.
bool g(T)(T)
{
return __traits(compiles, mixin("{ enum a = t; }"));
}
int a;
enum s = "";
// both return false but g(s) is expected to return true
pragma(msg, g(s));
pragma(msg, g(a));