On 13/12/13 16:52, Marco Leise wrote:
Most non-trivial ranges do the actual work in `popFront()' and
return a cached value from `front'. It has been argued as a
design quirk, that this in general leads to:

struct Range
{
   bool popFrontHasBeenCalledOnce = false;
   T current;

   @property T front()
   {
     if (!popFrontHasBeenCalledOnce)
     {
       popFront();  // initializes `current'
     }
     return current;
   }

   […]
}

For example in much of std.random. With classes you can get round it by defining a default constructor, but with structs it can create some tricky situations.

I have wondered about the feasibility of a method called something like .first() which would basically be called the very first time one calls _any_ method of the struct/class in question, and would perform the appropriate initialization.

Reply via email to