a variadic list of types of the arguments
import std.exception : assertThrown; import std.format : FormatException; import std.typecons : tuple; auto complete = "hello!34.5:124".formattedRead!(string, double, int)("%s!%s:%s"); assert(complete == tuple("hello", 34.5, 124)); // reading ends early assertThrown!FormatException("hello!34.5:".formattedRead!(string, double, int)("%s!%s:%s"));
Skipping values
import std.format : FormatException; import std.typecons : tuple; auto result = "orange: (12%) 15.25".formattedRead!(string, double)("%s: (%*d%%) %f"); assert(result == tuple("orange", 15.25));
The format string can be checked at compile-time
import std.exception : assertThrown; import std.format : FormatException; import std.typecons : tuple; auto expected = tuple("hello", 124, 34.5); auto result = "hello!124:34.5".formattedRead!("%s!%s:%s", string, int, double); assert(result == expected); assertThrown!FormatException("hello!34.5:".formattedRead!("%s!%s:%s", string, double, int));
Compile-time consistency check
import std.format : FormatException; import std.typecons : tuple; static assert(!__traits(compiles, "orange: (12%) 15.25".formattedRead!("%s: (%*d%%) %f", string, double)));
Reads an input range according to a format string and returns a tuple of Args with the read values.
Format specifiers with format character 'd', 'u' and 'c' can take a '*' parameter for skipping values.
The second version of formattedRead takes the format string as template argument. In this case, it is checked for consistency at compile-time.