D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14302 - New style opSlice doesn't compile
Summary: New style opSlice doesn't compile
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-17 19:28 UTC by Ilya Ivanov
Modified: 2022-02-14 13:04 UTC (History)
1 user (show)

See Also:


Attachments
Test case (5.61 KB, text/x-dsrc)
2015-03-17 19:28 UTC, Ilya Ivanov
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Ilya Ivanov 2015-03-17 19:28:11 UTC
Created attachment 1493 [details]
Test case

According to the documentation at http://dlang.org/operatoroverloading.html slice operators should be rewritten like
a.opIndexUnary!("$(METACODE op)")(a.opSlice(i, j))
a.opIndexAssign(c, a.opSlice(i, j))
a.opIndexOpAssign!("$(METACODE op)")(c, a.opSlice(i, j))
but currently this code is not compiled. The test case is in the attachment.
Comment 1 Kenji Hara 2015-06-02 01:58:07 UTC
If you want to use new integrated array operator overloading mechanism, you should make the opSlice member function for i..j a template, like as:

    //Slice opSlice(size_t i, size_t j)     // NG
    Slice opSlice(size_t dim)(size_t i, size_t j)  // OK
    {
        Slice slice = Slice(i, j);
        return slice;
    }

After the rewriting, all tests will pass.
Comment 2 RazvanN 2022-02-14 13:04:37 UTC
I cannot reproduce the failure.