Switch between two structs with csvreader
Selim Ozel
sozel at wpi.edu
Fri Nov 6 19:17:53 UTC 2020
On Thursday, 5 November 2020 at 22:36:36 UTC, Anonymouse wrote:
> If I'm not mistaken the `csvReader` function returns a range
> struct, and the full type is something long and unwieldy like
> `CsvReader!(struct_type1, cast(Malformed)1, string, dchar,
> string[])`. So just think of `records` as being that.
I actually first going this route but couldn't figure out the
correct name for that data type. It is quite long.
> You need two different variables and two different `foreach`es.
> For the same code to work on both types, the easy solution is
> templates. Perhaps make the `foreach` part after the reads a
> templated function that accepts any type passed to it?
Embedding the foreach loop inside a template function and
deciding on the data type at the higher level function solved my
issue. Thanks for the pointer!
Best,
Selim
More information about the Digitalmars-d-learn
mailing list