Error: variable i cannot be read at compile time

thedeemon dlang at thedeemon.com
Fri Jan 5 17:59:32 UTC 2018


On Friday, 5 January 2018 at 17:50:13 UTC, thedeemon wrote:
> Here's my version of solution. I've used ordinary arrays 
> instead of std.container.array, since the data itself is in 
> GC'ed heap anyway.
> I used csv file separated by tabs, so told csvReader to use 
> '\t' for delimiter.

And since lines of the file are copied to heap anyway, it's 
easier to skip unnecessary line splitting and joining and do the 
reading simpler:

import std.file : readText;

auto readData(string fname) {
     Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of tuples
     foreach (record; 
fname.readText.csvReader!(Tuple!ColumnTypes)('\t'))
         foreach(i, T; ColumnTypes)
             res[i] ~= record[i];
     return res;
}



More information about the Digitalmars-d-learn mailing list