Thread overview |
---|
August 23, 2014 Compile-Time Value Trait | ||||
---|---|---|---|---|
| ||||
I'm looking for a trait, say isCTExpression, that can check whether an alias parameter is an expression evaluable during compile-time? Have anybody written such a thing? |
August 23, 2014 Re: Compile-Time Value Trait | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 23 August 2014 at 22:12:06 UTC, Nordlöw wrote: > I'm looking for a trait, say isCTExpression, that can check I just say http://forum.dlang.org/thread/mailman.1953.1373509028.13711.digitalmars-d@puremagic.com Is this still the preferred way to do it? |
August 23, 2014 Re: Compile-Time Value Trait | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 23 August 2014 at 22:14:34 UTC, Nordlöw wrote: > On Saturday, 23 August 2014 at 22:12:06 UTC, Nordlöw wrote: As a complement I came up with /** Check if the value of $(D expr) is known at compile-time. See also: http://forum.dlang.org/thread/owlwzvidwwpsrelpkbok@forum.dlang.org */ enum isCTEable(alias id) = __traits(compiles, { enum idAlias = id; }); unittest { static assert(isCTEable!11); enum x = 11; static assert(isCTEable!x); auto y = 11; static assert(!isCTEable!y); } |
Copyright © 1999-2021 by the D Language Foundation