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

Tobi G. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 11 04:59:05 PST 2016


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


More information about the Digitalmars-d-learn mailing list