Accessors, byLine, input ranges

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jan 29 08:26:38 PST 2010


Steven Schveighoffer wrote:
> On Fri, 29 Jan 2010 11:18:46 -0500, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> wrote:
> 
>> Steven Schveighoffer wrote:
>>> On Fri, 29 Jan 2010 10:53:50 -0500, Michel Fortin 
>>> <michel.fortin at michelf.com> wrote:
>>>
>>>> On 2010-01-29 10:49:34 -0500, "Steven Schveighoffer" 
>>>> <schveiguy at yahoo.com> said:
>>>>
>>>>> ugh... much simpler with a true stream-like range that supports 
>>>>> what is  natural for streams:
>>>>>  for(int i = 0; i < count && !range.empty; i++) {
>>>>>     elements ~= range.get();
>>>>> }
>>>>>  But of course, then this function doesn't work for other range 
>>>>> types.  I  decided in that discussion long ago that stream ranges 
>>>>> were going to suck.
>>>>
>>>> You can always define a generic take() like this:
>>>>
>>>>     E take(R, E)(ref R range) {
>>>>         E element = range.front;
>>>>         range.popFront();
>>>>         return element;
>>>>     }
>>>>
>>>> This will work for any forward range.
>>>>
>>>  Except stream ranges.  I don't get it...
>>
>> It should work for stream ranges if front() checks the "filled" flag 
>> and eats the next line if false, and popFront clears the "filled" flag.
> 
> That actually makes a lot of sense.  I hope this fix goes in.

http://d.puremagic.com/issues/show_bug.cgi?id=3752

Andrei



More information about the Digitalmars-d mailing list