Please vote once and for good: range operations

Yigal Chripun yigal100 at gmail.com
Wed Jan 28 22:51:04 PST 2009


Andrei Alexandrescu wrote:
> Simen Kjaeraas wrote:
>> Andrei Alexandrescu wrote:
>>
>>> So please let's vote once and for all.
>>>
>>> Andrei
>>
>> Do let's. My first vote goes to first/last, with head/toe at second
>> place.
>>
>> --
>> Simen
>
> Ok, after looking at my code I discovered a huge problem with "first".
> ("Last" is cool.) If all you do is implement them and use them with
> foreach, fine. But if you need to call them manually (which is the case
> sometimes), you get really badly interacting terms there. Look at this,
> taken from real code (the filter function):
>
> while (!_input.empty && !pred(_input.first)) _input.next;
>
> I can see the putative user scratching their head: "Ok, so I start
> iteration with the first element, then I move to the next one... but
> then why the heck am I looking at the first again?"
>
> "First" must go.
>
>
> Andrei

I like the following from Chad's list:
begin/end
current/last
current/back
first/last
front/back
left/right
head/last
head/back
start/end
start/last

my preffered choice would be first/last.

regarding the above point:
_all_ ranges have a "head" but "tow" is optional, so maybe the desire 
for symetry is less important. how about current/last?

while (!_input.empty && !pred(_input.current)) _input.next;

also, I'd prefer to have a positive test instead of a negative one:

while (_input.more && !pred(_input.current)) _input.next;

but I could live with the current "empty".






More information about the Digitalmars-d mailing list