Thread overview | |||||
---|---|---|---|---|---|
|
February 06, 2018 Error: template std.conv.parse cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
I get this error when I try the following code: struct Record { union { ubyte[8] bytes; ulong l;} uint key; } Record r; r.l = parse!ulong("deadbeef", 16); However the following works: string s = "deadbeef"; r.l = parse!ulong(s, 16); And another way that works: r.l = "deadbeef".to!ulong(16); I've been doing C/C++ for over 20 years and recently started playing with D. I think the template overloading for parse is getting confused because it sees the lvalue r.l as being of type union rather than ulong. Is this a bug or the way things are supposed to work? |
February 06, 2018 Re: Error: template std.conv.parse cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ralph Doncaster | On Tuesday, 6 February 2018 at 17:33:43 UTC, Ralph Doncaster wrote: > I get this error when I try the following code: parse specifically works with a reference input it can advance. From the docs: "It takes the input by reference. (This means that rvalues - such as string literals - are not accepted: use to instead.) It advances the input to the position following the conversion." > I think the template overloading for parse is getting confused because it sees the lvalue r.l as being of type union rather than ulong. The left hand side of an assignment never plays a role in overloading, so you can disregard that. It is just a string literal cannot be advanced and thus does not work with parse. |
February 06, 2018 Re: Error: template std.conv.parse cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Tuesday, 6 February 2018 at 17:47:30 UTC, Adam D. Ruppe wrote:
> On Tuesday, 6 February 2018 at 17:33:43 UTC, Ralph Doncaster wrote:
>> I get this error when I try the following code:
>
> parse specifically works with a reference input it can advance. From the docs:
>
> "It takes the input by reference. (This means that rvalues - such as string literals - are not accepted: use to instead.)
> It advances the input to the position following the conversion."
>
>> I think the template overloading for parse is getting confused because it sees the lvalue r.l as being of type union rather than ulong.
>
> The left hand side of an assignment never plays a role in overloading, so you can disregard that. It is just a string literal cannot be advanced and thus does not work with parse.
Thanks! Got it.
|
Copyright © 1999-2021 by the D Language Foundation