Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document multidimensional array op overloading #625

Merged
merged 5 commits into from Aug 8, 2014

Conversation

quickfur
Copy link
Member

@quickfur quickfur commented Aug 7, 2014

Cf. dmd pull: dlang/dmd#443

@9rnsr
Copy link
Contributor

9rnsr commented Aug 7, 2014

Excellent!

An additional point: In arr[1, 2..3, $], arr is always evaluated only once, even when it is a function call. For example, foo()[1, 2..3, $; is rewritten to auto __tmp = foo(); __tmp.opIndex(1, __tmp.opSlice!1(2, 3), __tmp.opDollar!2());

Can you documenti the behavior?

@quickfur
Copy link
Member Author

quickfur commented Aug 7, 2014

What about opDollar? Is it also only evaluated once if it occurs multiple times within the same parameter? E.g., is arr[$/2 - sqrt($)] equivalent to:

auto __tmp = arr.opDollar!1;
arr.opIndex(__tmp/2 - sqrt(__tmp));

?

@9rnsr
Copy link
Contributor

9rnsr commented Aug 7, 2014

Yes, opDollar is also evaluated at most once in each dimensions.

@quickfur
Copy link
Member Author

quickfur commented Aug 7, 2014

Updated. Anything else?

@9rnsr
Copy link
Contributor

9rnsr commented Aug 8, 2014

Nothing. Thanks!

9rnsr added a commit that referenced this pull request Aug 8, 2014
Document multidimensional array op overloading
@9rnsr 9rnsr merged commit 42ac18f into dlang:master Aug 8, 2014
@quickfur quickfur deleted the multidim_overload branch August 8, 2014 14:47
@MartinNowak
Copy link
Member

There is no code example on how to integrate opIndex and opSlice, e.g. this does not work.

struct Array
{
    auto opIndex(size_t[2] bounds)
    {
        return ary[bounds[0] .. bounds[1]];
    }
    size_t[2] opSlice(size_t lwr, size_t upr)
    {
        return [lwr, upr];
    }
    ubyte[] ary;
}

But this does.

struct Array
{
    auto opIndex(size_t[2] bounds)
    {
        return ary[bounds[0] .. bounds[1]];
    }
    size_t[2] opSlice(size_t dim)(size_t lwr, size_t upr)
    {
        return [lwr, upr];
    }
    ubyte[] ary;
}

@quickfur
Copy link
Member Author

quickfur commented Sep 8, 2015

#1095

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants