On Friday, 27 March 2015 at 00:50:34 UTC, Hugo wrote:
On Thursday, 26 March 2015 at 12:29:03 UTC, John Colvin wrote:
On Thursday, 26 March 2015 at 12:21:23 UTC, Hugo wrote:
Also, can anyone provide a similar example but using little
endian order? If only to contrast differences between modes
of invocation...
void main() {
import std.stdio, std.array, std.bitmanip, std.system;
auto buffer = appender!(const ubyte[])();
buffer.append!(ushort, Endian.littleEndian)(261);
assert(buffer.data == [5, 1]);
writefln("%s", buffer.data);
}
Thanks, although it puzzles me that one has to move the type
inside the parenthesis and the value after them, otherwise it
doesn't compile.
It looks quite irregular, at least to someone like me, more
used to function than templates. :(
Think of it as compile-time arguments and run-time arguments.
First set of parenthesis are compile-time, second are run-time.
The parenthesis are optional for compile-time arguments iff
there's only one of them.
I wish one could simply append a buffer using the concatenation
operator, which would be the obvious choice, but it doesn't
seem to work for ubytes...
I agree that std.bitmanip often doesn't have the most intuitive
interface.