Bug 11921 – dmd doesn't like expressions in templates, only values
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-13T12:20:39Z
Last change time
2018-10-19T05:38:30Z
Assigned to
No Owner
Creator
Andrew Pennebaker
Comments
Comment #0 by apennebaker — 2014-01-13T12:20:39Z
I want to parse a substring into an integer. I try:
ios7crypt.d:
...
string hash = "104306170e120b";
auto seed = parse!(int)(hash[0..2]);
...
But dmd complains:
ios7crypt.d(68): Error: template std.conv.parse does not match any function template declaration.
To get around this, I can separate parsing into two steps.
ios7crypt.d:
...
string hash = "104306170e120b";
string seed_str = hash[0..2];
auto seed = parse!(int)(seed_str);
...
The second snippet compiles and runs. I just wish I didn't have to do this; that the template syntax could handle nested expressions.
Full source, in case anyone would like more context:
https://github.com/mcandre/ios7crypt/tree/master/d
Comment #1 by eco — 2014-01-13T12:45:17Z
This is actually because parse() takes a ref source and that slice is an rvalue.
I recommend doing this instead:
auto seed = hash[0..2].to!int;
Comment #2 by pro.mathias.lang — 2018-10-19T05:38:30Z
As mentioned, this is due to ref, and not a DMD bug. Closing.