Conditional Attributes
Steven Schveighoffer
schveiguy at gmail.com
Fri Feb 21 01:41:21 UTC 2020
On 2/18/20 12:11 PM, Marcel wrote:
> Hello!
>
> Say I have a struct where every member function can either be static or
> not depending on a template parameter. Is there a simple way to do this?
> Like, for example:
>
> struct Foo(Condition)
> {
> static if (Condition) static:
>
> void Bar() {}
> void Baz() {}
>
> }
Since D conditional compilation must always be a valid declaration or
statement, you cannot do something like this.
The closest you can do is to use mixins, which means you have to write
everything inside strings.
It has been proposed quite a few times to have a way to enable/disable
attributes based on a compile-time boolean. But it's never come close to
getting included.
-Steve
More information about the Digitalmars-d-learn
mailing list