Issue 10407 - std.conv.to of lazy range to numbers array
Summary: std.conv.to of lazy range to numbers array
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P4 enhancement
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-06-18 10:47 UTC by bearophile_hugs
Modified: 2024-12-01 16:17 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-06-18 10:47:23 UTC
import std.regex: splitter, regex;
import std.conv: to;
import std.array: array;
void main() {
    auto s = splitter("10 30 20", r"[\s,]+".regex);
    auto r1 = s.array.to!(real[]); // OK
    auto r2 = s.to!(real[]); // Error
}


DMD 2.063.2 gives:

...\dmd2\src\phobos\std\conv.d(276): Error: template std.conv.toImpl does not match any function template declaration. Candidates are:
...\dmd2\src\phobos\std\conv.d(332):        std.conv.toImpl(T, S)(S value) if (isImplicitlyConvertible!(S, T) && !isEnumStrToStr!(S, T) && !isNullToStr!(S, T))
...\dmd2\src\phobos\std\conv.d(445):        std.conv.toImpl(T, S)(ref S s) if (isRawStaticArray!S)
...\dmd2\src\phobos\std\conv.d(461):        std.conv.toImpl(T, S)(S value) if (is(typeof(S.init.opCast!T()) : T) && !isExactSomeString!T)
...\dmd2\src\phobos\std\conv.d(492):        std.conv.toImpl(T, S)(S value) if (!isImplicitlyConvertible!(S, T) && is(T == struct) && is(typeof(T(value))))
...\dmd2\src\phobos\std\conv.d(542):        std.conv.toImpl(T, S)(S value) if (!isImplicitlyConvertible!(S, T) && is(T == class) && is(typeof(new T(value))))
...\dmd2\src\phobos\std\conv.d(276):        ... (16 more, -v to show) ...
...\dmd2\src\phobos\std\conv.d(332): Error: template std.conv.toImpl cannot deduce template function from argument types !(real[])(Splitter!(string, Regex!char))
...\dmd2\src\phobos\std\conv.d(276): Error: template instance toImpl!(real[]) errors instantiating template
test.d(7): Error: template instance std.conv.to!(real[]).to!(Splitter!(string, Regex!char)) error instantiating
Comment 1 hsteoh 2015-09-08 17:11:58 UTC
Is this a real bug? Couldn't you just do `s.map!(a => a.to!real).array` to do what you want?
Comment 2 bearophile_hugs 2015-09-18 08:55:47 UTC
(In reply to hsteoh from comment #1)
> Is this a real bug?

No, it's an enhancement request...


> Couldn't you just do `s.map!(a => a.to!real).array` to do what you want?

Yes, but I think converting lazy ranges is a basic and common need, so it should be supported by "to".
Comment 3 dlangBugzillaToGithub 2024-12-01 16:17:59 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9607

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB