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 DM to convert

Examples

1 ushort[] arr;
2 auto app = appender(arr);
3 write!float(app, 1.0f);
4 
5 
6 auto app = appender!(const(ushort)[]);
7 app.write!ushort(5);
8 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 = [
8    0, 0x3f80,
9    0, 0, 0, 0x4000];
10 app.data.shouldEqual(expected);

Write ushort and int

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

Meta