How is this pure function able to modify non-private state?
问题 TDPL, p. 167: as long as the mutable state in a function is entirely transitory (i.e., allocated on the stack) and private (i.e., not passed along by reference to functions that may taint it), then the function can be considered pure. import std.stdio : writeln; struct M{ int[4] _data; pure ref int opIndex(size_t i){ return _data[i]; } } pure M foo(ref M m){ m[0] = 1234; return m; } void main(){ M m1 = M([7, 7, 7, 7]); writeln(m1); foo(m1); writeln(m1); } // output: // M([7, 7, 7, 7]) // M(