Simple way to handle rvalues and templates.

Salih Dincer salihdb at hotmail.com
Sun Feb 27 09:25:31 UTC 2022


On Sunday, 27 February 2022 at 06:11:28 UTC, Ali Çehreli wrote:
>
> I don't like the name readFrom() yet but that works. :)
>

It seems very delicious, can stay as read():

```d
auto read(T, Endian E = Endian.bigEndian, R)
              (R range) {
   import bop = std.bitmanip;
   return bop.read!(T, E)(range);
}

void main() {
   import std.system;

   ubyte[8] d = [ 0xFF, 0xFF, 0xFF, 0xFF,
                  0xAA, 0xAA, 0xFF, 0xFF ];

   ushort us = d[4..6].read!ushort;
   assert(us == 0xAAAA);
}
```
SDB79


More information about the Digitalmars-d-learn mailing list