write

Writes numeric type T into a output range of ushort.

void
write
(
T
R
)
(
ref R output
,
T n
)
if (
isOutputRange!(R, ushort)
)

Parameters

n
Type: T

The numeric type to write into output range

output
Type: R

The output range of word to convert

Examples

1 ushort[] arr;
2 auto app = appender(arr);
3 write!float(app, 1.0f);
4 
5 auto app = appender!(const(ushort)[]);
6 app.write!ushort(5);
7 app.data.shouldEqual([5]);

Write float and double

1 ushort[] arr;
2 auto app = appender(arr);
3 write!float(app, 1.0f);
4 
5 app.write!double(2.0);
6 
7 ushort[] expected = [0, 0x3f80, 0, 0, 0, 0x4000];
8 assert(app.data == expected);

Write ushort and int

1 import std.array : appender;
2 
3 auto app = appender!(const(ushort)[]);
4 app.write!ushort(5);
5 assert(app.data == [5]);
6 
7 app.write!float(1.964F);
8 assert(app.data == [5, 0x645A, 0x3ffb]);
9 
10 app.write!uint(0x1720_8034);
11 assert(app.data == [5, 0x645A, 0x3ffb, 0x8034, 0x1720]);

Meta