Comment #0 by john.loughran.colvin — 2015-03-02T15:30:32Z
struct S
{
auto opIndex(size_t i)
{
return 1;
}
auto opIndexUnary(string s)(size_t i, size_t j)
{
return -1;
}
}
unittest
{
S s;
assert(-s[0] == -1);
}
this fails to compile because the compiler won't fall back to using opIndex when it can't find an applicable opIndexUnary
Comment #1 by john.loughran.colvin — 2015-03-02T16:12:37Z
The same goes for opIndexAssign, opIndexOpAssign and so on... Once you define one possible overload, nothing will fall back to using opIndex and then applying the operation to the result.
Comment #2 by robert.schadek — 2024-12-13T18:40:43Z