On Thursday, 28 March 2013 at 20:24:50 UTC, Vidar Wahlberg wrote:
To follow up with some new woes I'm currently struggling with:
I'm storing some various values in an ubyte array. I discovered
that it's probably std.bitmanip I wish to use in order to
"convert" i.e. an int to 4 bytes (although I went first to
std.conv looking for this feature).
--snip--
I am completely confused as to why you're doing what you are
doing ... std.conv does work (and in the case you've listed, is
unnecessary anyway). Try this:
import std.stdio, std.conv;
void main() {
ubyte[] buffer;
buffer ~= 5; // Simple solution
buffer ~= to!ubyte(6); // Proper usage of "to"
writeln(buffer);
}
---
Now, for performance reasons you might want to use appender (or
buffer.reserve(n), if you happen to know how many items you'll be
storing), but the simplest thing works.