dupping to allow vector operation?

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 9 11:01:26 PDT 2014


On Thursday, 9 October 2014 at 11:29:14 UTC, bearophile wrote:
> Observe:
>
> void main() {
>      int[3] a1 = [1, 3, 6];
>      int[]  a2 = a1[] * 3;       // line 3, Error
>      int[]  a3 = a1.dup[] *= 3;  // line 4, OK?
>      int[]  a4 = (a1[] * 3).dup; // line 5, Error
> }
>
>
> Currently the operation in line 4 is accepted:
>
> test.d(3,17): Error: array operation a1[] * 3 without 
> destination memory not allowed
> test.d(5,18): Error: array operation a1[] * 3 without 
> destination memory not allowed
>
> Is it a good idea to support something like line 5?
>
> Bye,
> bearophile

Why not? Looks fine to me, you've explicitly allocated some new 
memory for the result to sit in, the lack of which is the 
motivation for lines 3 an 5 being errors.


More information about the Digitalmars-d-learn mailing list