version(StdDoc)

Stanislav Blinov stanislav.blinov at gmail.com
Sun Nov 25 07:19:50 UTC 2018


On Sunday, 25 November 2018 at 05:41:56 UTC, H. S. Teoh wrote:
> On Sat, Nov 24, 2018 at 05:48:16PM +0000, Stanislav Blinov via 
> Digitalmars-d-learn wrote:

>> Yup. UDAs did get in there eventually, and version should too.
>
> I think this would be a trivial DIP, by making it such that a 
> version block inside an enum would lower to the above code. Of 
> course, it could be taken further: the above trick doesn't 
> quite handle this case:
>
> 	enum E {
> 		a,
> 		version(Windows) {
> 			b, c
> 		}
> 		version(Posix) {
> 			d
> 		}
> 	}

That is what Jonathan (and I concur) is talking about.

> But this looks like such an antipattern that it probably should 
> be written differently anyway, or just generated via a string 
> mixin.

Why is it an antipattern? Having to version the whole enum just 
because some stupid C API has two out of a hundred items 
versioned per platform is an antipattern :)

Granted, it may require some special syntax, i.e.

enum E {
     a,
     b if version(Windows),
     c if version(Windows),
     d if version(Posix),
}

or something to that effect. But there has to be a better way 
than just versioning the whole enum or resorting to clumsy mixins.


More information about the Digitalmars-d-learn mailing list