On 23/03/14 08:53, Jonathan M Davis wrote:
But again, front and empty should normally function as if they were variables.
They should be property functions and should be pure (or at least act like
they're pure). I'm sure that a _lot_ of code will break if that isn't
followed.
There are some not-very-nice exceptions to that in std.random, where in many of
the range types you have stuff along the following lines:
auto front() @property
{
if (notInitialized)
{
init();
}
return _value;
}
see e.g. MersenneTwister, RandomSample, and others. It's all a nasty
consequence of that RNGs-as-value-types problem we've discussed previously.
However, the class-based std.random2 that is being discussed on the announce
list fixes that:
http://forum.dlang.org/thread/[email protected]
In general though, I think that most of us would agree that front and empty
should be treated as properties - i.e. as if they were variables - and that
they should have try to stick to those semantics as closely as possible.
Ranges that stray from that seriously risk not working with a lot of range-
based code.
Yes, absolutely.