View source code
Display the source code in std/bitmanip.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.bitmanip.peek
Takes a range of ubyte
s and converts the first T
bytes to
T
. The value returned is converted from the given endianness to the
native endianness. The range is not consumed.
T peek(T, Endian endianness = Endian .bigEndian, R)
(
R range
)
if (canSwapEndianness!T && isForwardRange!R && is(ElementType!R : const(ubyte)));
T peek(T, Endian endianness = Endian .bigEndian, R)
(
R range,
size_t index
)
if (canSwapEndianness!T && isForwardRange!R && hasSlicing!R && is(ElementType!R : const(ubyte)));
T peek(T, Endian endianness = Endian .bigEndian, R)
(
R range,
size_t* index
)
if (canSwapEndianness!T && isForwardRange!R && hasSlicing!R && is(ElementType!R : const(ubyte)));
Parameters
Name | Description |
---|---|
T | The integral type to convert the first T bytes to. |
endianness | The endianness that the bytes are assumed to be in. |
range | The range to read from. |
index | The index to start reading from (instead of starting at the
front). If index is a pointer, then it is updated to the index
after the bytes read. The overloads with index are only
available if hasSlicing!R is true . |
Example
ubyte[] buffer = [1, 5, 22, 9, 44, 255, 8];
writeln(buffer .peek!uint()); // 17110537
writeln(buffer .peek!ushort()); // 261
writeln(buffer .peek!ubyte()); // 1
writeln(buffer .peek!uint(2)); // 369700095
writeln(buffer .peek!ushort(2)); // 5641
writeln(buffer .peek!ubyte(2)); // 22
size_t index = 0;
writeln(buffer .peek!ushort(&index)); // 261
writeln(index); // 2
writeln(buffer .peek!uint(&index)); // 369700095
writeln(index); // 6
writeln(buffer .peek!ubyte(&index)); // 8
writeln(index); // 7
Example
import std .algorithm .iteration : filter;
ubyte[] buffer = [1, 5, 22, 9, 44, 255, 7];
auto range = filter!"true"(buffer);
writeln(range .peek!uint()); // 17110537
writeln(range .peek!ushort()); // 261
writeln(range .peek!ubyte()); // 1
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, Alex Rønne Petersen, Damian Ziemba, Amaury SECHET
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.