File.byRecord

Creates an input range set up to parse one line at a time from the file into a tuple.

Range primitives may throw StdioException on I/O error.

template byRecord(Fields...)
byRecord
(
string format
)

Parameters

format

tuple record _format

Return Value

The input range set up to parse one line at a time into a record tuple.

Examples

static import std.file;
import std.typecons : tuple;

// prepare test file
auto testFile = std.file.deleteme();
scope(failure) printf("Failed test at line %d\n", __LINE__);
std.file.write(testFile, "1 2\n4 1\n5 100");
scope(exit) std.file.remove(testFile);

File f = File(testFile);
scope(exit) f.close();

auto expected = [tuple(1, 2), tuple(4, 1), tuple(5, 100)];
uint i;
foreach (e; f.byRecord!(int, int)("%s %s"))
{
    assert(e == expected[i++]);
}

See Also

It is similar to byLine and uses _format under the hood.

Meta