tomaszkam / date

A date and time library based on the C++11/14/17 <chrono> header
Other
0 stars 0 forks source link

[LWG3221] Result of year_month arithmetic with months is ambiguous #8

Closed tomaszkam closed 5 years ago

tomaszkam commented 5 years ago

Original comment:

constexpr year_month operator+(const yearmonth& ym, const months& dm) noexcept; Returns: A year­month value z such that z - ym == dm. Complexity: O(1) with respect to the value of dm.

a) This is not enough to uniquely pin down the value of z. I think we need to say that z.ok() is true.

E-mail thread: [isocpp-lib] year_month arithmetic

tomaszkam commented 5 years ago

Discussion: The current specification of the addition of year_month and months does not define unique result value. To illustrate, both year(2019)/month(1) and year(2018)/month(13) are valid results of year(2018)/month(12) + months(1) addition, according to the spec in [time.cal.ym.nonmembers] (http://eel.is/c++draft/time.cal.ym.nonmembers#3).

Proposed wording: Apply the following changes to the specification of operator+ in [time.cal.ym.nonmembers]: constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; Returns: A year_­month value z such that z.ok() && z - ym == dm. Complexity: O(1) with respect to the value of dm.

tomaszkam commented 5 years ago

This is already implemented. Add new unit test to cover !year_month::ok() values. https://github.com/HowardHinnant/date/pull/425