Range to array

2012-06-29 Thread Namespace
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 im

Re: Range to array

2012-06-29 Thread Jonathan M Davis
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

Re: Range to array

2012-06-30 Thread Namespace
std.range already publicly import std.array. Oh, good to known. 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 somethi

Re: Range to array

2012-06-30 Thread Jonathan M Davis
On Saturday, June 30, 2012 11:06:06 Namespace wrote: > But a Range don't match any function that accept arrays. Or > should i prefer to use Ranges instead of arrays? In general, functions should take ranges, not arrays. They're far more flexible that way. Requiring an array is generally overly re

Re: Range to array

2012-06-30 Thread bearophile
Namespace: Or should i prefer to use Ranges instead of arrays? There is no short answer to this question. Arrays and lazy ranges have different qualities, so they are better for different situations. Arrays use more memory, but in some situations they are faster. Lazy ranges can be a little

How to append range to array?

2015-05-23 Thread Vladimir Panteleev via Digitalmars-d-learn
int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); Hopefully in one GC allocation (assuming we know the range's length). I tried std.range.primitives.put but its behavior seems a little mysterious: This compiles but asserts at runtime: int[] arr = [1, 2, 3

Re: How to append range to array?

2015-05-23 Thread Atila Neves via Digitalmars-d-learn
std.range.chain? Atila On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev wrote: int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); Hopefully in one GC allocation (assuming we know the range's length). I tried std.range.primitives.put but its beh

Re: How to append range to array?

2015-05-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 23, 2015 07:03:33 Vladimir Panteleev via Digitalmars-d-learn wrote: > int[] arr = [1, 2, 3]; > auto r = iota(4, 10); > // ??? > assert(equal(arr, iota(1, 10))); > > Hopefully in one GC allocation (assuming we know the range's > length). > > I tried std.range.primitives.put but its

Re: How to append range to array?

2015-05-23 Thread weaselcat via Digitalmars-d-learn
On Saturday, 23 May 2015 at 08:35:45 UTC, weaselcat wrote: On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev wrote: int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); import std.array : array; arr ~ r.array; woops, meant ~= but this is probably f

Re: How to append range to array?

2015-05-23 Thread weaselcat via Digitalmars-d-learn
On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev wrote: int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); import std.array : array; arr ~ r.array;

Re: How to append range to array?

2015-05-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 23, 2015 08:36:47 weaselcat via Digitalmars-d-learn wrote: > On Saturday, 23 May 2015 at 08:35:45 UTC, weaselcat wrote: > > On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev > > wrote: > >> int[] arr = [1, 2, 3]; > >> auto r = iota(4, 10); > >> // ??? > >> assert(equal(a

Re: How to append range to array?

2015-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/23/15 4:27 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Saturday, May 23, 2015 07:03:33 Vladimir Panteleev via Digitalmars-d-learn wrote: int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); Hopefully in one GC allocation (assuming we know the ran

Re: How to append range to array?

2015-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2015 22:13:25 Steven Schveighoffer via Digitalmars-d-learn wrote: > On 5/23/15 4:27 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > > On Saturday, May 23, 2015 07:03:33 Vladimir Panteleev via > > Digitalmars-d-learn wrote: > >> int[] arr = [1, 2, 3]; > >> auto r = iota(4,

Re: How to append range to array?

2015-05-25 Thread John Colvin via Digitalmars-d-learn
On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev wrote: int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); Hopefully in one GC allocation (assuming we know the range's length). I tried std.range.primitives.put but its behavior seems a little myst