Using std.conv.to with std.typecons.Typedef

Saurabh Das via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 11 05:24:23 PST 2016


On Monday, 11 January 2016 at 12:59:05 UTC, Tobi G. wrote:
> On Monday, 11 January 2016 at 12:15:55 UTC, Saurabh Das wrote:
>>
>> Any ideas?
>
> Yes. Because Typedef is introducing new Types, which csvReader 
> doesn't know what they are,
> you'll need a little workaround and cast the values yourself.
>
> import std.csv, std.stdio, std.algorithm, std.range;
>
> enum csvTxt = "10, 20
> 30, 40
> 50, 50";
>
> myStuff = csvTxt.csvReader!(Tuple!(long, long))
> 	.map!(a => MyStuff(cast(QuestionId)a[0], cast(StudentId) a[1]))
>         .array;
>
>
> The .map does nothing other as getting the information out of 
> the Tuple 'a' and constructing a struct of the type MyStuff.
>
> togrue

Yes that does make sense. I could read in a POD struct and 
convert it to a typed one.

Though I was hoping for a more elegant solution... This'll have 
to do I guess.

Thanks!



More information about the Digitalmars-d-learn mailing list