3104. Fixing duration division

Section: 30.5.6 [time.duration.nonmember] Status: C++20 Submitter: Johel Ernesto Guerrero Peña Opened: 2018-04-17 Last modified: 2021-02-25

Priority: 0

View all other issues in [time.duration.nonmember].

View all issues with C++20 status.

Discussion:

[time.duration.nonmember]/1 states

In the function descriptions that follow, CD represents the return type of the function.

From what I could find, many definitions of CD in the paragraphs of [time.duration.nonmember] were lifted to [time.duration.nonmember]/1 as cited above. That works for all other paragraphs, but not for [time.duration.nonmember]/10, which the change rendered ill-formed:

template<class Rep1, class Period1, class Rep2, class Period2>
  constexpr common_type_t<Rep1, Rep2>
    operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
Returns: CD(lhs).count() / CD(rhs).count().

In this case, we want CD to mean common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>. That way, the division has the expected semantics of dividing two quantities of the same dimension.

[ 2018-04-24 Moved to Tentatively Ready after 6 positive votes on c++std-lib. ]

[2018-06 Rapperswil: Adopted]

Proposed resolution:

This wording is relative to N4741.

  1. Edit 30.5.6 [time.duration.nonmember] as indicated:

    -1- In the function descriptions that follow, unless stated otherwise, let CD represents the return type of the function.

    […]

    template<class Rep1, class Period1, class Rep2, class Period2>
      constexpr common_type_t<Rep1, Rep2>
        operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
    

    Let CD be common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>.

    -10- Returns: CD(lhs).count() / CD(rhs).count().