www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - struct construct with array

reply Caligo <iteronvexor gmail.com> writes:
--20cf307f309c77ee73049e4d7143
Content-Type: text/plain; charset=ISO-8859-1

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?

--20cf307f309c77ee73049e4d7143
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

struct Test{<br><br>=A0 public double[3] ar_;<br>=A0 this(double[3] ar){<br=
=A0=A0=A0 this.ar_ =3D ar;<br>=A0 }<br>}<br><br>void main(){<br><br>=A0 do=

<br>=A0 auto t1 =3D Test(v1[0..$] + v2[0..$]);=A0=A0=A0=A0 // error<br>

one line, but I&#39;m getting an error.=A0 Any ideas?<br> --20cf307f309c77ee73049e4d7143--
Mar 12 2011
parent reply =?ISO-8859-1?Q?Ali_=C7ehreli?= <acehreli yahoo.com> writes:
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
Mar 12 2011
parent =?ISO-8859-1?Q?Ali_=C7ehreli?= <acehreli yahoo.com> writes:
On 03/12/2011 02:52 PM, Ali Çehreli wrote:
 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

I see from the other posts that the problem has something to do with auto. This works: double[3] v3 = v1[] + v2[]; Ali
Mar 12 2011