problems with std.bitmanip.append (bug?)

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 26 05:29:02 PDT 2015


On Thursday, 26 March 2015 at 12:21:23 UTC, Hugo wrote:
> On Thursday, 26 March 2015 at 10:07:07 UTC, Hugo wrote:
>>
>> If only the documentation and/or test units were more clear...
>
> OK, I made a simpler test, using an example from the 
> documentation:
>
>
> void main() {
>    import std.stdio, std.array, std.bitmanip;
>    auto buffer = appender!(const ubyte[])();
>    buffer.append!ushort(261);
>    assert(buffer.data == [1, 5]);
>    writefln("%s", buffer.data);
> }
>
> It seems to work, so apparently one has to explicitly create a 
> buffer with the appender template. Not terribly useful IMHO.
>
> Wouldn't it be possible for the append function to automaticaly 
> change the mode of an already existing buffer?
>
> 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);
}


More information about the Digitalmars-d-learn mailing list