Comment #0 by ilyayaroshenko — 2016-09-06T13:26:11Z
-------------------------------------------
import std.experimental.ndslice;
void main()
{
auto sl = new double[10].sliced(2, 5);
auto d = -sl[0, 1];
}
-------------------------------------------
/d921/f269.d(6): Error: template std.experimental.ndslice.slice.Slice!(2LU, double*).Slice.opIndexUnary cannot deduce function from argument types !("-")(int, int), candidates are:
/opt/compilers/dmd2/include/std/experimental/ndslice/slice.d(1980): std.experimental.ndslice.slice.Slice!(2LU, double*).Slice.opIndexUnary(string op, Indexes...)(Indexes _indexes) if (isFullPureIndex!Indexes && (op == "++" || op == "--"))
/opt/compilers/dmd2/include/std/experimental/ndslice/slice.d(2008): std.experimental.ndslice.slice.Slice!(2LU, double*).Slice.opIndexUnary(string op, Slices...)(Slices slices) if (isFullPureSlice!Slices && (op == "++" || op == "--"))
-------------
The are two prototypes in Slice. Both with if (op == "++" || op == "--") condition.
So, I don't think we need to add all opIndexUnary variants.
Instead, if expression -sl[0, 1] can not be expanded with opIndexUnary, then is should be expanded with -(sl.opIndex(0, 1)).
Comment #1 by clumsycodemonkey — 2016-09-25T01:50:48Z
I was able to fix it by adding `-` to the list of accepted strings in the if statement. So now the function signature looks like this
--------------------
auto ref opIndexUnary(string op, Indexes...)(Indexes _indexes)
if (isFullPureIndex!Indexes && (op == `++` || op == `--` || op == `-`))
--------------------
This works for the case reported in the original ticket. Not sure what to do about the overload that takes slices. The semantically typical thing to do would be return a new slice with a new array underneath it that has the negated values, so as to not modify the underlying array. But that would cause an allocation.
Comment #2 by ilyayaroshenko — 2016-09-25T12:07:38Z
(In reply to Ryan from comment #1)
> I was able to fix it by adding `-` to the list of accepted strings in the if
> statement. So now the function signature looks like this
> --------------------
> auto ref opIndexUnary(string op, Indexes...)(Indexes _indexes)
> if (isFullPureIndex!Indexes && (op == `++` || op == `--` || op
> == `-`))
> --------------------
>
> This works for the case reported in the original ticket. Not sure what to do
> about the overload that takes slices. The semantically typical thing to do
> would be return a new slice with a new array underneath it that has the
> negated values, so as to not modify the underlying array. But that would
> cause an allocation.
This is a workaround, which generate more template bloat. We need DMD FE bug fix
Comment #3 by github-bugzilla — 2016-09-30T15:19:38Z