Just to be sure I'm not trying to solve an issue that doesn't needs to be solved: Given
date d = day(33) / month(5) / 2013;
Note that I has a typo on the day. This is equivalent on my implementation to
date d(year(2013), month(5), day(33));
If I want to throw a bad date exception I would need to check that the day/month and year are in range. Next follows the code:
days_date::days_date(year y, month m, day d) { if (set_if_valid_date(y, m, d)) return; throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '-' + to_string(m)); }
bool days_date::set_if_valid_date(year y, month m, day d) noexcept { // [0] bool leap = is_leap(y.value()); // [1] const day_of_year::rep* year_data = days_in_year_before(leap);
if (!(d.value() <= year_data[m.value()] - year_data[m.value()-1])) // [2] { return false; } year::rep by = y.value() + 32799; // [3] x_ = days_before_year(by) + year_data[m.value()-1] + d.value(); // [4] return true; }
I have a question here. Why are we not throwing the exception from set_if_valid_date() itself? Why did we include noexcept in its definition? -- View this message in context: http://boost.2283326.n4.nabble.com/gsoc-2013-draft-proposal-for-chrono-date-... Sent from the Boost - Dev mailing list archive at Nabble.com.