2011/2/5 Andrei Alexandrescu <[email protected]>: > I hereby suggest we define "buffered input range of T" any range R that > satisfies the following conditions: > > 1. R is an input range of T[] > > 2. R defines a primitive shiftFront(size_t n). The semantics of the > primitive is that, if r.front.length >= n, then shiftFront(n) discards the > first n elements in r.front. Subsequently r.front will return a slice of the > remaining elements. > > 3. R defines a primitive appendToFront(size_t n). Semantics: adds at most n > more elements from the underlying stream and makes them available in > addition to whatever was in front. For example if r.front.length was 1024, > after the call r.appendToFront(512) will have r.front have length 1536 of > which the first 1024 will be the old front and the rest will be newly-read > elements (assuming that the stream had enough data). If n = 0, this > instructs the stream to add any number of elements at its own discretion.
This is really cool. I realise now that appendToFront fills the gap in the design providing only shiftFront/advance. I also thought their names were well-chosen. Torarin
