RFC on range design for D2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Sep 12 08:39:36 PDT 2008
Steven Schveighoffer wrote:
> "Bill Baxter" wrote
>> I think one thing to consider is what it will take to make a new
>> container support and "play nice" with the regime proposed. This
>> touches on Andrei's point about being hard pressed to think of generic
>> algorithms to run on an HMM, too.
>>
>> The first question is who do you want to "play nice" with? If you're
>> going to be writing functions specifically for that container, then
>> you don't really have to play nice with anyone. Your container just
>> needs to have the operations necessary to support those functions.
>
> Bill, thanks so much for explaining it like this, I really agree with what
> you say. My concern is that iterator is going to become a 'bad word' and
> considered a flawed design.
>
> But you are right, there is no need for iterators to be allowed for
> std.algorithm, I totally agree with that, I just assumed Andrei meant
> iterators would be discouraged for everything, including general use as
> pointers into container objects. If that is not the case, then I
> wholeheartedly agree that algorithms should be restricted to ranges, and
> iterators should be used only in container operations.
You are right. Iterators can definitely be handy in many situations, and
it took me some hair pulling to figure out how to do moveToFront with
ranges alone. (Then admittedly it's a pretty wicked algorithm no matter
what.)
I don't want to discourage defining iterators, but rather not force you
to define them when you define a new range, and also force people who
want to use std.algorithm in learning them in addition to ranges.
Andrei
More information about the Digitalmars-d-announce
mailing list