version(StdDoc)

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Nov 25 05:41:56 UTC 2018


On Sat, Nov 24, 2018 at 05:48:16PM +0000, Stanislav Blinov via Digitalmars-d-learn wrote:
> On Saturday, 24 November 2018 at 17:43:35 UTC, Jonathan M Davis wrote:
> > On Saturday, November 24, 2018 9:28:47 AM MST Stanislav Blinov via
> > Digitalmars-d-learn wrote:
[...]
> > > enum Foo
> > > {
> > >      a,
> > >      b,
> > >      c = {
> > >         version(linux) return 42;
> > >         else version(Windows) return 54;
> > >      } ()
> > > }
> > > 
> > > /pedantry
> > 
> > LOL. That's an interesting trick. It's ugly and hacky, but it does
> > work around the problem.
> 
> :)

That's an awesome trick! Genius.


> > I'm still inclined to think though that it should be legal to just
> > use version directly in the member list.
> 
> 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
		}
	}

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


T

-- 
Knowledge is that area of ignorance that we arrange and classify. -- Ambrose Bierce


More information about the Digitalmars-d-learn mailing list