`s >> date::parse()` does not ignore space as `s >> integer` do
(v3.0.1)
std::istringstream is("123 2020.12.11T09:11:12.123");
is >> integer_a >> date::parse("%Y.%m.%dT%H:%M:%S", timepoint);
This will fail to extract time from the stream.
Maybe it is more consistent with the current behavior of operator>>(istream, v) to make date::parse skip "space" chars automatically?
You can modify the format string to match a wide variety of white space characters:
- a white space character matches zero or more white space characters
- %n matches one white space character
- %t matches zero or one white space characters.
These can be combined to match even more patterns. For example "%n " matches one or more white space charcters, and "%n%t%t" matches one to three white space characters.
Thank you Howard, but I'm talking about the convention:
For standard streams, the
skipwsflag is set on initialization.
So the behavior of is>>date(parse) might be not consistent with this default standard assumption (i.e. skipws is set by default).
parse is a manipulator for calling from_stream. from_stream is documented to be consistent with other unformatted input functions (e.g. getline). The rationale for choosing this behavior is because the formatting is supplied by the fmt string argument which provides better whitespace control than do the formatted input functions (which have no way to control whitespace in the input other than skipws).
This behavior is now part of C++20, and efforts to change it have to be directed to the C++ Standards Committee (WG21). The "date" library now serves as a preview of this part of C++20 for those clients who can not yet migrate to C++20. Therefore to the extent practical, the date lib will follow the C++20 specification (though there are deviations made for practical reasons).