Smooth transition to D2 for Tango users?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Sep 22 15:00:36 PDT 2008
"Sergey Gromov" wrote
> Bruce Adams <tortoise_74 at yeah.who.co.uk> wrote:
>> I don't think its unreasonable to expect that braces will be balanced
>> in all future versions of the language.
>
> Braces can be in strings or comments. It's quite likely to have braces
> in strings in many kinds of parser programs.
>
> If you want code hidden from a compiler, put it in a string and mix in.
>
> enum veryD2Code = `
> auto foo(T)(T x) if (__traits(hasMember, "opCall"))
> {
> return x();
> }
> `;
>
> version (D_Version2)
> {
> mixin(veryD2Code);
> }
>
> In D2 you can use token strings for that purpose, so that the code will
> even be highlighted in your editor, but will not interfere with the
> compiler.
oops, D1 doesn't support that type of enum ;)
If the problem can't be solved with the current compilers, then the solution
provided to make it work should be easy to use. I don't see this type of
solution as easy to use, nor the 'version(D2)' type of solution. What if
you have const member functions? If we had a preprocessor, I'd say:
#ifdef Dv2
const int f()
#else
int f()
#endif
But we don't, so the reality is you must duplicate the function just to
change the signature. Unless you do some hacky stuff like the mixin above.
The two best solutions I've read are the original post (make D1 compile D2
as if it were D1), and a D2toD1 translator program.
-Steve
More information about the Digitalmars-d
mailing list