digitalmars.D.learn - How to convert ubyte[] to uint?
- Dr.No (16/16) May 23 2018 read fails with both uint and ulong on 64bit platform:
- Jonathan M Davis (7/23) May 23 2018 As the template constraint in the error message says, read requires an i...
- Dr.No (6/15) May 23 2018 sorry, the error message wasn't clear to me. When I use dynamic
- Steven Schveighoffer (11/30) May 23 2018 I'm guessing you wrote:
read fails with both uint and ulong on 64bit platform: Error: template std.bitmanip.read cannot deduce function from argument types !(ulong)(ubyte[8]), candidates are: C:\ldc2-1.9.0-windows-x64\bin\..\import\std\bitmanip.d(3213,3): std.bitmanip.read(T, Endian endianness = Endian.bigEndian, R)(ref R range) if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const(ubyte))) code: import digestx.fnv; import std.bitmanip : read; FNV64 fnv64; fnv64.start(); fnv64.put(cast(ubyte[])word); ubyte[8] arr = fnv64.finish(); auto h = arr.read!ulong; return cast(uint)h;
May 23 2018
On Wednesday, May 23, 2018 19:36:07 Dr.No via Digitalmars-d-learn wrote:read fails with both uint and ulong on 64bit platform: Error: template std.bitmanip.read cannot deduce function from argument types !(ulong)(ubyte[8]), candidates are: C:\ldc2-1.9.0-windows-x64\bin\..\import\std\bitmanip.d(3213,3): std.bitmanip.read(T, Endian endianness = Endian.bigEndian, R)(ref R range) if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const(ubyte))) code: import digestx.fnv; import std.bitmanip : read; FNV64 fnv64; fnv64.start(); fnv64.put(cast(ubyte[])word); ubyte[8] arr = fnv64.finish(); auto h = arr.read!ulong; return cast(uint)h;As the template constraint in the error message says, read requires an input range. Static arrays are not input ranges. You need to give it a dynamic array - and since read takes its argument by reference, you can't simply slice the static array and pass it. You need a variable that's a dynamic array. - Jonathan M Davis
May 23 2018
On Wednesday, 23 May 2018 at 19:49:27 UTC, Jonathan M Davis wrote:On Wednesday, May 23, 2018 19:36:07 Dr.No via Digitalmars-d-learn wrote:sorry, the error message wasn't clear to me. When I use dynamic arrays I get: slice of static array temporary returned by fnv64.finish() assigned to longer lived variable arr What should use instead of?[...]As the template constraint in the error message says, read requires an input range. Static arrays are not input ranges. You need to give it a dynamic array - and since read takes its argument by reference, you can't simply slice the static array and pass it. You need a variable that's a dynamic array. - Jonathan M Davis
May 23 2018
On 5/23/18 3:53 PM, Dr.No wrote:On Wednesday, 23 May 2018 at 19:49:27 UTC, Jonathan M Davis wrote:I'm guessing you wrote: ubyte[] arr = fnv64.finish(); ?? You want: auto arrtmp = fnv64.finish(); auto arr = arrtmp[]; Basically, what you were doing is allocating some stack space to hold a static array that immediately goes out of scope, and then storing a slice to it. -SteveOn Wednesday, May 23, 2018 19:36:07 Dr.No via Digitalmars-d-learn wrote:sorry, the error message wasn't clear to me. When I use dynamic arrays I get: slice of static array temporary returned by fnv64.finish() assigned to longer lived variable arr What should use instead of?[...]As the template constraint in the error message says, read requires an input range. Static arrays are not input ranges. You need to give it a dynamic array - and since read takes its argument by reference, you can't simply slice the static array and pass it. You need a variable that's a dynamic array. - Jonathan M Davis
May 23 2018