using parse with string slice
Quentin Ladeveze via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Dec 5 14:07:47 PST 2015
On Saturday, 5 December 2015 at 22:05:11 UTC, anonymous wrote:
> On 05.12.2015 22:59, Quentin Ladeveze wrote:
>> ---
>> import std.conv;
>>
>> string s = "1B2A";
>>
>> int value = parse!int(s[0..2], 16); //template std.conv.parse
>> cannot
>> deduce function from argument types !(int)(string, int)
>> ---
>>
>> Does someone have an idea of why it happens ? The version of
>> parse that
>> is used here is :
>>
>> ---
>> std.conv.parse(Target, Source)(ref Source s, uint radix) if
>> (isSomeChar!(ElementType!Source) && isIntegral!Target &&
>> !is(Target ==
>> enum))
>> ---
>>
>> And I can't see which template constraint is not respected
>> when I call
>> it with a slice.
>
> It's the `ref` part. A slice expression cannot be passed in a
> ref parameter. You can use std.conv.to instead or assign the
> slice to a variable first.
Thank you for your quick answer, learned something today :)
More information about the Digitalmars-d-learn
mailing list