-
-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Something to extend an array with a lazy range #9978
Labels
Comments
andrej.mitrovich (@AndrejMitrovic) commented on 2013-05-26T06:21:09ZHmm, 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\phobos\std\array.d(587): Attempting to fetch the front of an empty array of int |
bearophile_hugs commented on 2013-05-26T13:12:23ZMore general issue summary. |
issues.dlang (@jmdavis) commented on 2013-05-26T17:22:46Z> 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. |
andrej.mitrovich (@AndrejMitrovic) commented on 2013-05-27T02:06:50Z(In reply to comment #3)
> > 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.
That makes sense now that I think about it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bearophile_hugs reported this on 2013-05-26T06:14:15Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=10176
CC List
Description
The text was updated successfully, but these errors were encountered: