Why is std.algorithm so complicated to use?

Christophe Travert travert at phare.normalesup.org
Tue Jul 10 10:33:24 PDT 2012


"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.

I don't like makeRange much. Would you have a better name? smallRange? 
rangeOf?




More information about the Digitalmars-d mailing list