Why is std.algorithm so complicated to use?
Daniel Murphy
yebblies at nospamgmail.com
Tue Jul 10 10:36:02 PDT 2012
"Christophe Travert" <travert at phare.normalesup.org> wrote in message
news:jthp14$30em$1 at digitalmars.com...
> "Daniel Murphy" , dans le message (digitalmars.D:171741), a écrit :
>> "Christophe Travert" <travert at phare.normalesup.org> wrote in message
>> news:jthmu8$2s5b$1 at digitalmars.com...
>>> "Daniel Murphy" , dans le message (digitalmars.D:171720), a écrit :
>>>> Could it be extended to accept multiple values? (sort of like chain)
>>>> eg.
>>>> foreach(x; makeRange(23, 7, 1990)) // NO allocations!
>>>> {
>>>> ....
>>>> }
>>>> I would use this in a lot of places I currently jump through hoops to
>>>> get
>>>> a
>>>> static array without allocating.
>>>
>>> That's a good idea. IMHO, the real solution would be to make an easy way
>>> to create static arrays, and slice them when you want a range.
>>
>> It's not quite the same thing, static arrays are not ranges and once you
>> slice them you no longer have a value type, and might be referring to
>> stack
>> allocated data. With... this thing, the length/progress is not encoded
>> in
>> the type (making it rangeable) but the data _is_ contained in the type,
>> making it safe to pass around. The best of both worlds, in some
>> situations.
>
> OK, I see. This goes against the principle that ranges are small and
> easy to copy arround, but it can be useful when you know what you are
> doing, or when the number of items is small.
>
Yeah, it works where you'd pass a tuple of elements of the same type, but
want to iterate over it.
> I don't like makeRange much. Would you have a better name? smallRange?
> rangeOf?
>
>
rangeit
More information about the Digitalmars-d
mailing list