From e6b1e0fe584337e76b27b80e3831d7397aea33df Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Mon, 24 Jul 2017 08:18:18 -0400 Subject: [PATCH] Allow read_unsigned to read 0 digits * Will allow reading "optional" integers. --- date.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/date.h b/date.h index 734b2e6..5876bed 100644 --- a/date.h +++ b/date.h @@ -5297,7 +5297,7 @@ read_signed(std::basic_istream& is, unsigned m = 1, unsigned M = { if (c == '-' || c == '+') (void)is.get(); - auto x = static_cast(read_unsigned(is, m, M)); + auto x = static_cast(read_unsigned(is, std::max(m, 1u), M)); if (!is.fail()) { if (c == '-') @@ -5306,7 +5306,8 @@ read_signed(std::basic_istream& is, unsigned m = 1, unsigned M = } } } - is.setstate(std::ios::failbit); + if (m > 0) + is.setstate(std::ios::failbit); return 0; }