www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11921] New: dmd doesn't like expressions in templates, only values

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11921

           Summary: dmd doesn't like expressions in templates, only values
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: apennebaker 42six.com


--- Comment #0 from Andrew Pennebaker <apennebaker 42six.com> 2014-01-13
12:20:39 PST ---
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

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11921


Brad Anderson <eco gnuk.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eco gnuk.net


--- Comment #1 from Brad Anderson <eco gnuk.net> 2014-01-13 12:45:17 PST ---
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;

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2014