pop

Takes an input range of words (ushort) and converts the first T.sizeof / 2 words to T. The array is consumed.

T
pop
(
T
R
)
(
ref R input
)
if (
(isInputRange!R) &&
is(ElementType!R : const ushort)
)

Parameters

T

The integral type to convert the first T.sizeof / 2 word to.

input
Type: R

The input range of words to convert

Examples

pop!float example

1 ushort[] asPeek = [0x645A, 0x3ffb];
2 assert(asPeek.pop!float == 1.964F);
3 assert(asPeek.length == 0);
4 
5 // float.sizeOf is 4bytes => 2 word
6 ushort[] input = [0x1eb8, 0xc19d];
7 assert(input.length == 2);
8 assert(pop!float(input) == -19.64F);
9 assert(input.length == 0);
10 
11 input = [0x0, 0xBF00, 0x0, 0x3F00];
12 assert(input.pop!float == -0.5F);
13 assert(pop!float(input) == 0.5F);

pop!double examples.

A double has size 8 bytes => 4word

1 ushort[] input = [0x0, 0x0, 0x0, 0x3FE0];
2 assert(input.length == 4);
3 
4 assert(pop!double(input) == 0.5);
5 assert(input.length == 0);
6 
7 input = [0x0, 0x0, 0x0, 0xBFE0];
8 assert(pop!double(input) == -0.5);
9 
10 input = [0x00, 0x01, 0x02, 0x03];
11 assert(input.length == 4);
12 assert(pop!int(input) == 0x10000);
13 assert(input.length == 2);
14 assert(pop!int(input) == 0x30002);
15 assert(input.length == 0);

pop!ushort and short examples

1 ushort[] input = [0xFFFF, 0xFFFF, 0xFFFB, 0xFFFB];
2 assert(pop!ushort(input) == 0xFFFF);
3 assert(pop!short(input) == -1);
4 assert(pop!ushort(input) == 0xFFFB);
5 assert(pop!short(input) == -5);

Meta