This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.
duration is missingoperator%Section: 30.5[time.duration]Status:C++11Submitter: Terry GolubiewskiOpened: 2008-11-30Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [time.duration].
View all issues withC++11 status.
Discussion:
Addresses US 81
duration is missingoperator%. This operator is convenientfor computing where in a time frame a givenduration lies. Amotivating example is converting aduration into a "broken-down"time duration such as hours::minutes::seconds:
class ClockTime{ typedef std::chrono::hours hours; typedef std::chrono::minutes minutes; typedef std::chrono::seconds seconds;public: hours hours_; minutes minutes_; seconds seconds_; template <class Rep, class Period> explicit ClockTime(const std::chrono::duration<Rep, Period>& d) : hours_ (std::chrono::duration_cast<hours> (d)), minutes_(std::chrono::duration_cast<minutes>(d % hours(1))), seconds_(std::chrono::duration_cast<seconds>(d % minutes(1))) {}};[Summit:]
Agree except that there is a typo in the proposed resolution. The memberoperators should be
operator%=.
[Batavia (2009-05):]
We agree with the proposed resolution.Move to Tentatively Ready.
[2009-07 Frankfurt]
Moved from Tentatively Ready to Open only because the wording needs to beimproved for enable_if type constraining, possibly following Robert'sformula.
[2009-07 Frankfurt:]
Howard to open a separate issue (1177(i)) to handle the removal of memberfunctions from overload sets, provide wording, and possibly demonstratehow this can be implemented using enable_if (see947(i)).
Move to Ready.
Proposed resolution:
Add to the synopsis in 30[time]:
template <class Rep1, class Period, class Rep2> duration<typename common_type<Rep1, Rep2>::type, Period> operator%(const duration<Rep1, Period>& d, const Rep2& s);template <class Rep1, class Period1, class Rep2, class Period2> typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
Add to the synopsis ofduration in 30.5[time.duration]:
template <class Rep, class Period = ratio<1>>class duration {public: ...duration& operator%=(const rep& rhs);duration& operator%=(const duration& d); ...};Add to 30.5.4[time.duration.arithmetic]:
duration& operator%=(const rep& rhs);Effects:
rep_ %= rhs.Returns:
*this.duration& operator%=(const duration& d);Effects:
rep_ %= d.count().Returns:
*this.
Add to 30.5.6[time.duration.nonmember]:
template <class Rep1, class Period, class Rep2> duration<typename common_type<Rep1, Rep2>::type, Period> operator%(const duration<Rep1, Period>& d, const Rep2& s);Requires:
Rep2shall be implicitly convertible toCR(Rep1, Rep2)andRep2shall not be an instantiation ofduration. Diagnostic required.Returns:
duration<CR, Period>(d) %= s.template <class Rep1, class Period1, class Rep2, class Period2> typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);Returns:
common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type(lhs) %= rhs.