opIndexUnary post in-/decrement how to ?
Ali Çehreli
acehreli at yahoo.com
Wed Jul 14 19:37:45 UTC 2021
On 7/14/21 11:27 AM, Tejas wrote:
> the compiler error should have been a dead giveaway
> that opIndex was returning a _constant_ value
I know you mean "rvalue" but if I may be unnecessarily pedantic, an
rvalue can indeed be mutated:
struct A {
int i;
void mutate() {
i = 42;
import std.stdio;
writeln("I am not constant. :)");
}
}
struct B {
auto opUnary(string op)() {
return A();
}
}
void main() {
auto b = B();
(++b).mutate(); // <-- Mutating an rvalue
}
Ali
More information about the Digitalmars-d-learn
mailing list