Range to array

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 29 17:05:30 PDT 2012


On Saturday, June 30, 2012 01:43:44 Namespace wrote:
> It is terrible to use a function of std.range if you are not
> using "auto" as type all the time.
> Why isn't there a convert function for the original type?
> I know "array(Range)" of std.array is what i want, but why do i
> have to import two  modules to use one?
> Wouldn't it be better if std.range imports std.array implicit?
> Otherwise (IMO) std.range needs some convert functions like

std.range already publicly import std.array.

Not to mention, if you're using ranges heavily, it's not all that uncommon to 
not actually need std.array.array very often. In general, if you're constantly 
converting ranges to arrays, then I'd argue that you're doing something wrong. 
There are definitely times when you need to convert a range to an array, but in 
general, you can just pass the result of one range-based function to another 
and operate on the data just fine without needing to convert to arrays at all. 
Worst case, you convert once you're done with all of various operations that 
you need to do on the data. But if you're passing arrays around rather than 
ranges, unless you actually need arrays for some reason, you should really 
consider passing ranges around like Phobos does. You're code's not going to be 
terribly efficient if you're constantly converting the results of range-based 
functions into arrays, since that means allocating more memory for the same 
data every time that you do that.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list