On 3/26/15 6:07 AM, Hugo wrote:
On Thursday, 26 March 2015 at 02:39:56 UTC, Steven Schveighoffer wrote:
An array as an output range writes to the front. You can use
std.array.Appender to get appending behavior. I know, it's weird.
Alternatively, you can add more bytes to the array, and append to the
slice, but that may be ugly/hard to do.
Hmm... isnt that't what the std.bitmanip.write function is for? It even
provides an index.
Quite possibly write and append do the same thing for arrays because of
the way slices support the output range idiom.
Perhaps I have found a bug. Actually I am not sure because I am not yet
familiar with the way to use templates, so there is the possibility that
I am using incorrect arguments.
No, it's not a bug. A slice does not support appending in the way you
expect as an output range.
Think of a slice/array as a buffer in which to put information, maybe
it's a stack buffer. If you output to this buffer, you wouldn't expect
it to allocate more memory and append to the end would you? Instead,
you'd expect to write data starting at the beginning.
If you want append behavior, use std.array.Appender, as is described in
the example of std.bitmanip.append.
I do, however, think that the term "append" is very misleading. If it
were named "putInto", that might have been a less confusing term.
-Steve