Why does formattedRead take a non-const ref?
Andrew Godfrey via Digitalmars-d
digitalmars-d at puremagic.com
Thu Aug 28 21:21:52 PDT 2014
The first parameter of formattedRead is a non-const ref. Is there
a good reason for this?
e.g. the below doesn't compile, but if I remove the 'const' from
Foo.normalize, then it succeeds:
unittest {
import std.datetime;
struct Foo {
string date;
DateTime normalize() const {
import std.format, std.exception;
int month, day, year;
enforce(3 == formattedRead(date, "%d/%d/%d", &month,
&day, &year));
return DateTime(year, month, day, 0, 0, 0);
}
}
Foo foo = Foo("12/2/2014");
assert(foo.normalize == DateTime(2014, 12, 2, 0, 0, 0));
}
More information about the Digitalmars-d
mailing list