Are iterators and ranges going to co-exist?
Peter Alexander
peter.alexander.au at gmail.com
Tue Jul 20 00:39:48 PDT 2010
On 20/07/10 4:27 AM, PercentEwe wrote:
> As for space usage, well, sometimes ranges can give you an improvement, and in the
> worst case, a range is a struct with begin and end C++ iterators as its members.
> It's a space improvement unless you don't actually need to iterate through
> anything, in which case, why are you using an iterator?
What else do you propose I use?
Pointers will work for arrays, but what about lists? You want to point
to nodes in lists. To handle this is a general setting, you need an
abstract coordinate structure, a.k.a iterator, or cursor.
>> In the thread on improving std.algorithm.find, there were mentions of
>> making find (or some findFirst) that returned a single element. Would
>> this be an iterator, or a single value range?
>
> Again, why are you using an iterator? Or a range, or enumerable, or what have you?
> I guess it's a tad easier than: bool tryFind(range, element, out position); or
> returning a struct containing a success flag and the element found.
See above.
Iterator is probably a bad name for describing this concept, as it
implies that they have the same usage as ranges, but they do not. An
iterator/cursor points to one element -- a generic pointer if you like.
Ranges define a self-sufficient machine for iteration, which makes them
overkill (and unwieldy) when you just want to refer to one element.
More information about the Digitalmars-d
mailing list