This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.
duration arithmetic: contradictory requirementsSection: 30.5.6[time.duration.nonmember]Status:ResolvedSubmitter: Pete BeckerOpened: 2008-12-20Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [time.duration.nonmember].
View all issues withResolved status.
Discussion:
In 30.5.6[time.duration.nonmember], paragraph 8 says that callingdur / rep whenrep is an instantiation ofduration requires a diagnostic. That's followed by anoperator/ that takes two durations. Sodur1 / dur2 is legal under the second version,but requires a diagnostic under the first.
[Howard adds:]
Please see the thread starting with c++std-lib-22980 for more information.
[Batavia (2009-05):]
Move to Open, pending proposed wording (and preferably an implementation).
[2009-07-27 Howard adds:]
I've addressed this issue under the proposed wording for1177(i) whichcleans up several places under 30.5[time.duration] which used thephrase "diagnostic required".
For clarity's sake, here is an example implementation of the constrained
operator/:template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>struct __duration_divide_result{};template <class _Duration, class _Rep2, bool = is_convertible<_Rep2, typename common_type<typename _Duration::rep, _Rep2>::type>::value>struct __duration_divide_imp{};template <class _Rep1, class _Period, class _Rep2>struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>{ typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;};template <class _Rep1, class _Period, class _Rep2>struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false> : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>{};template <class _Rep1, class _Period, class _Rep2>inlinetypename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::typeoperator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s){ typedef typename common_type<_Rep1, _Rep2>::type _Cr; duration<_Cr, _Period> __r = __d; __r /= static_cast<_Cr>(__s); return __r;}
__duration_divide_resultis basically a custom-builtenable_ifthat will containtypeonly ifRep2is not adurationand ifRep2is implicitly convertible tocommon_type<typename Duration::rep, Rep2>::type.__is_durationis simply a private trait that answersfalse, but is specialized fordurationto answertrue.The constrained
operator%works identically.
[2009-10 Santa Cruz:]
Proposed resolution: