problems with std.bitmanip.append
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 25 19:40:01 PDT 2015
On 3/25/15 1:29 PM, Hugo wrote:
> On Wednesday, 25 March 2015 at 17:09:05 UTC, John Colvin wrote:
>> As per the signature in the docs:
>>
>> void append(T, Endian endianness = Endian.bigEndian, R)(R range, T value)
>>
>> The endianness is the second template argument. What you need to write is
>>
>> buffer.append!(uint,
>> Endian.littleEndian)(cast(uint)stdTimeToUnixTime(Clock.currStdTime));
>>
>> or
>>
>> append!(uint, Endian.littleEndian)(buffer,
>> cast(uint)stdTimeToUnixTime(Clock.currStdTime));
>>
>> Note that you don't need to specify the third template argument, that
>> will be inferred automatically from the type of `buffer`
>
> Hmm... the examples for append in the documentation look very different
> from the syntax you have suggested. No wonder.
>
> In any case, I have tried the code with the first way you suggested, and
> append actually does not append to the buffer, but... rewrites the buffer!
>
> Since the buffer is not static, shouldn't append actually do that?
>
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.
-Steve
More information about the Digitalmars-d-learn
mailing list