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

1 static import std.file;
2 import std.typecons : tuple;
3 
4 // prepare test file
5 auto testFile = std.file.deleteme();
6 scope(failure) printf("Failed test at line %d\n", __LINE__);
7 std.file.write(testFile, "1 2\n4 1\n5 100");
8 scope(exit) std.file.remove(testFile);
9 
10 File f = File(testFile);
11 scope(exit) f.close();
12 
13 auto expected = [tuple(1, 2), tuple(4, 1), tuple(5, 100)];
14 uint i;
15 foreach (e; f.byRecord!(int, int)("%s %s"))
16 {
17     assert(e == expected[i++]);
18 }

See Also

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

Meta

Suggestion Box / Bug Report