D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7015 - Allow vector operations into newly declared array
Summary: Allow vector operations into newly declared array
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic, spec
Depends on:
Blocks:
 
Reported: 2011-11-25 17:05 UTC by bearophile_hugs
Modified: 2024-12-07 13:31 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-11-25 17:05:12 UTC
While writing some D code that uses vectors and the desire to find distances among them, I'd like this vector operation to be supported:


void main() {
    int[] a = [1, 2, 3];
    int[] b = a[] ^^ 2;
}


DMD 2.057head gives:

test.d(3): Error: Array operation a[] ^^ 2 not implemented
Comment 1 Stewart Gordon 2011-12-10 08:58:48 UTC
How, exactly, does this differ from (marked fixed) issue 3661?
Comment 2 bearophile_hugs 2011-12-10 10:36:52 UTC
(In reply to comment #1)
> How, exactly, does this differ from (marked fixed) issue 3661?

Thank you Stewart, you are right. Vector pow is already implemented:


import std.math, std.stdio;
void main() {
    int[3] a = [1, 2, 3];
    int[3] b;
    b = a[] ^^ 2;
    writeln(b);
    a[] ^^= 2;
    writeln(a, " ", b);
}


So this is a:
1) A diagnostic bug, because the error message is misleading.
2) It shows a more general design problem with vector operations, because code like this too is refused with a similar error message:

void main() {
    int[] a = [1, 2, 3];
    int[] b = a[] + 2;
}

Vector ops require the memory needed to store the result to be already present. I don't know if this will change.

What do you suggest to do with this bug report, to close it?
Comment 3 Stewart Gordon 2011-12-10 17:18:34 UTC
So the language currently doesn't allow vector ops into a newly declared array.

So this is really two things:
(a) as you say, a diagnostic bug, as the error message when you try to do it is bogus
(b) a language feature request to allow this code

I'm guessing (a) and (b) need to be filed as two separate issues.  But meanwhile, I'm changing the summary line so that it at least makes sense.
Comment 4 Ryuichi OHORI 2015-08-27 21:33:56 UTC
(In reply to Stewart Gordon from comment #3)
> So this is really two things:
> (a) as you say, a diagnostic bug, as the error message when you try to do it
> is bogus
> (b) a language feature request to allow this code

Maybe (b) is a duplicate of 2548
Comment 5 dlangBugzillaToGithub 2024-12-07 13:31:36 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17115

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB