struct construct with array

Ali Çehreli acehreli at yahoo.com
Sat Mar 12 14:52:14 PST 2011


On 03/12/2011 10:42 AM, Caligo wrote:
> struct Test{
>
>    public double[3] ar_;
>    this(double[3] ar){
>      this.ar_ = ar;
>    }
> }
>
> void main(){
>
>    double[3] v1 = [1.0, 2.0, 3.0];
>    double[3] v2 = [2.0, 3.0, 4.0];
>
>    auto t1 = Test(v1[0..$] + v2[0..$]);     // error
>
> }
>
>
> I want to add those two arrays and call the constructor in one line, but I'm
> getting an error.  Any ideas?
>

Even a simpler code doesn't work:

     double[3] v1 = [1.0, 2.0, 3.0];
     double[3] v2 = [2.0, 3.0, 4.0];

     auto result = v1[0..$] + v2[0..$];

Error: Array operation v1[0LU..__dollar] + v2[0LU..__dollar] not implemented

The following doesn't work either:

     auto result = v1[] + v2[];
     auto result = v1 + v2;

dmd does not implement those features yet.

Ali


More information about the Digitalmars-d-learn mailing list