supporting DMD-1.016 and DMD-2.000 with the same source code
Carlos Santander
csantander619 at gmail.com
Mon Jun 18 11:44:13 PDT 2007
Thomas Kuehne escribió:
> 4) class invariants
> ===================
>
> This is the only real trouble spot so far. DMD-1 uses
> invariant{ ... assert(...); ... }
> however DMD-2 uses
> invariant(){ ... assert(...); ... }
>
> There are basically two approaches. Both require dmd_version from
> 1) "What compiler am I running?" (see above). First the complete
> mixin solution:
>
> # class Foo : Object{
> # int x;
> #
> # mixin("invariant" ~ (dmd_version < 2 ? "" : "()") ~
> # "{
> # assert(x < 100);
> # }");
> # }
>
> This might be a quick hack however in most cases you are going to
> lose nice features like syntax highlighting. Invariants are
> prohibited from calling 'public' member function but calling
> 'private' member functions is OK:
>
> # const char[] invariantCall = "invariant" ~ (dmd_version < 2 ? "" : "()")
> # ~ "{ invariant_(); }";
> #
> # class Foo : Object{
> # int x;
> #
> # mixin(invariantCall);
> #
> # private void invariant_(){
> # assert(x < 100);
> # }
> # }
>
To avoid this ugly hack, how about supporting invariant(){} in Dv1?
--
Carlos Santander Bernal
More information about the Digitalmars-d
mailing list