Moving from 1.0 to D2

Trass3r mrmocool at
Tue Mar 10 13:55:19 PDT 2009

jicman schrieb:
> Can the D1 code be easily changed to D2?  We are talking about more than 30K lines of code.

The most important change is constness.
I personally use the following compatibility "layer"; though it's aim is 
to provide compatibility with both D1 and D2 compilers and not 
completely porting to D2 it might be an inspiration for you.

The hard part is to determine which one you need; mutable, const or 

// define string types for compatibility with both D1 and D2
version (D_Version2)
	pragma(msg, "D2 detected. Taking care of constness.");

	// we need a mixin cause the code is syntactically illegal under D1
	alias const(char) cchar; /// const char type
	alias invariant(char) ichar; /// invariant char type

	alias char[] mstring; /// mutable string type
	alias const(char)[] cstring; /// const string type
	alias invariant(char)[] istring; /// invariant string type

	alias wchar[] mwstring;
	alias const(wchar)[] cwstring;
	alias invariant(wchar)[] iwstring;

	alias dchar[] mdstring;
	alias const(dchar)[] cdstring;
	alias invariant(dchar)[] idstring;`);
	pragma(msg, "D1 detected. All strings are mutable.");

	alias char cchar;
	alias char ichar;

	alias char[] mstring;
	alias char[] cstring;
	alias char[] istring;

	alias wchar[] mwstring;
	alias wchar[] cwstring;
	alias wchar[] iwstring;

	alias dchar[] mdstring;
	alias dchar[] cdstring;
	alias dchar[] idstring;

More information about the Digitalmars-d-learn mailing list