www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - immutable & alias this

reply bearophile <bearophileHUGS lycos.com> writes:
I find typedef useful still. While trying to create a poor's man typedef using
a struct with alis this, I have found this problem:



struct Typedef(T) {
    T data;
    alias data this;
}

alias int[] TA1;
typedef int[] TA2;
alias Typedef!(int[]) TA3;

immutable TA1 a1;
immutable TA2 a2;
TA3 a3a;
immutable TA3 a3b;

static this() {
    a1 = [1, 2, 3];  // OK
    a2 = [1, 2, 3];  // OK
    a3a = [1, 2, 3]; // OK
    a3b = [1, 2, 3]; // line 16, error
}
void main() {}



DMD 2.057beta gives:

test.d(16): Error: cannot implicitly convert expression ([1,2,3]) of type int[]
to immutable(Typedef!(int[]))

What do you think?

Bye,
bearophile
Nov 08 2011
parent Trass3r <un known.com> writes:
 test.d(16): Error: cannot implicitly convert expression ([1,2,3]) of  
 type int[] to immutable(Typedef!(int[]))
OT: this shows another possible problem. See http://clang.llvm.org/diagnostics.html, section "Typedef Preservation and Selective Unwrapping"
Nov 09 2011