www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - idup portable D1/D2

reply Frank Benoit <keinfarbton googlemail.com> writes:
I want to make code compilable with D1+D2.

So i thought, i can make

version(D_Version2){
} else { // D1
  string idup( char[] str ){ return str.dup; }
}

But this does not work.
D1:
str.idup;   // compile error
str.idup(); // OK

D2:
str.idup;   // OK
str.idup(); // compile error

Ideas?
Mar 25 2009
parent Frank Benoit <keinfarbton googlemail.com> writes:
hm, the moment of pressing the "send" button is often enough a moment of
enlightment :)

version( D_Version2 ){
    mixin("invariant(T)[] _idup(T)( T[] str ){ return str.idup; }");
} else { // D1
    String _idup( char[] str ){
        return str.dup;
    }
}

str._idup(); // compiles with D1+D2
Mar 25 2009