digitalmars.D.bugs - [Issue 10176] New: std.array.extend?
- d-bugmail puremagic.com (25/25) May 26 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10176
- d-bugmail puremagic.com (27/28) May 26 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10176
- d-bugmail puremagic.com (11/11) May 26 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10176
- d-bugmail puremagic.com (16/17) May 26 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10176
- d-bugmail puremagic.com (7/10) May 27 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10176
http://d.puremagic.com/issues/show_bug.cgi?id=10176
Summary: std.array.extend?
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
Maybe it's worth adding a std.array.extend() function that's similar to "~="
but accepts a lazy range (in theory, in a language where ranges are built-ins,
~= should append ranges too to arrays).
In std.array there is a join, but it creates a whole new array. It's usually
more efficient to extend arrays.
foreach (x; myrange)
myarray ~= x;
Is replaced by:
myarray.extend(myrange);
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10176
Andrej Mitrovic <andrej.mitrovich gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrej.mitrovich gmail.com
06:21:09 PDT ---
Hmm, I would have hoped that 'put' would work here, but it doesn't:
-----
import std.range;
import std.array;
void main()
{
{
Appender!(int[]) arr;
arr.put(iota(5)); // ok
assert(arr.data == [0, 1, 2, 3, 4]);
}
{
int[] arr;
arr.put(iota(5)); // runtime exception
assert(arr == [0, 1, 2, 3, 4]);
}
}
-----
core.exception.AssertError C:\dmd-git\dmd2\windows\bin\..\..\src\phob
s\std\array.d(587): Attempting to fetch the front of an empty array of int
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10176
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|std.array.extend? |Something to extend an
| |array with a lazy range
More general issue summary.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10176
Jonathan M Davis <jmdavisProg gmx.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jmdavisProg gmx.com
PDT ---
Hmm, I would have hoped that 'put' would work here, but it doesn't:
put on arrays does not append. It starts writing at the beginning of the array.
So, it functions fundamentally differently from most output ranges. Presumably,
it's the desired behavior if you're dealing with a pre-allocated chunk of
memory that you're trying to fill, but it is problematic in that it doesn't
function like other output ranges. I've been think of opening a discussion in
the newsgroup on it so that we can figure out how to better sort out some of
these quirks of output ranges.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10176 02:06:50 PDT ---That makes sense now that I think about it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------Hmm, I would have hoped that 'put' would work here, but it doesn't:put on arrays does not append. It starts writing at the beginning of the array.
May 27 2013









d-bugmail puremagic.com 