Allow read_unsigned to read 0 digits

* Will allow reading "optional" integers.
This commit is contained in:
Howard Hinnant
2017-07-24 08:18:18 -04:00
parent 170ebfd354
commit e6b1e0fe58

5
date.h
View File

@@ -5297,7 +5297,7 @@ read_signed(std::basic_istream<CharT, Traits>& is, unsigned m = 1, unsigned M =
{ {
if (c == '-' || c == '+') if (c == '-' || c == '+')
(void)is.get(); (void)is.get();
auto x = static_cast<int>(read_unsigned(is, m, M)); auto x = static_cast<int>(read_unsigned(is, std::max(m, 1u), M));
if (!is.fail()) if (!is.fail())
{ {
if (c == '-') if (c == '-')
@@ -5306,7 +5306,8 @@ read_signed(std::basic_istream<CharT, Traits>& is, unsigned m = 1, unsigned M =
} }
} }
} }
is.setstate(std::ios::failbit); if (m > 0)
is.setstate(std::ios::failbit);
return 0; return 0;
} }