Why D const is annoying

SomeDude lovelydear at mailmetrash.com
Sat Apr 28 03:00:29 PDT 2012


On Sunday, 11 December 2011 at 04:27:31 UTC, Mehrdad wrote:
> Another bug, this time regarding invariant()....
>
> (I think this is related to the previous one about int vs. 
> size_t in template parameters, but I'm not sure...)
>
>     template NArray(T, size_t N)
>     { static if (N > 0) { alias NArray!(T, N - 1)[] NArray; } 
> else { alias T NArray; } }
>     struct Tensor(T, Length...)
>     {
>         enum N = Length[0];
>         invariant() { }
>         this(scope NArray!(T, N) copyOfItems...) { }
>         @property T[] data() { return null; }
>         Tensor!(typeof(mixin("data[0] " ~ op ~ " data[0]")), N) 
> opBinary(string op)(Tensor other)
>         { return typeof(return).init; }
>     }
>     void main()
>     {
>         Tensor!(size_t, 1) a;
>         a = a + a;
>     }
>
> Error: this for __invariant needs to be type Tensor not type 
> Tensor!(uint,1)

This one is still valid.


More information about the Digitalmars-d mailing list