Stream Proposal
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Mar 14 10:48:12 PDT 2011
On 3/14/11 10:32 AM, Kagamin wrote:
> Andrei Alexandrescu Wrote:
>
>> A simple input buffered stream of T would be a range of T[] that has two
>> extra primitives:
>>
>> T[] lookAhead(size_t n);
>> void leaveBehind(size_t n);
>
> T front();
> T[] front(size_t n); // bulk front
> void popFront(size_t n=1); // bulk popFront
I think such an interface would be confusing. In particular, if T is
int, the overload of front looks awfully close to a property writer.
>> I'm not sure there's a need for formalizing a buffered output interface
>> (we could simply make buffering transparent, in which case there's only
>> need for primitives that get and set the size of the buffer).
>>
>> In case we do want to formalize an output buffer, it would need
>> primitives such as:
>>
>> T[] getBuffer(size_t n);
>> void commitBuffer(size_t n);
>
> void put(T); // as usual
> void put(T[]); // bulk put; can pass a slice of the buffer from getBuffer
This is already implemented but doesn't allow someone to play with the
buffer and then commit it. Arguably there might be no such need.
Andrei
More information about the Digitalmars-d
mailing list