This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
chrono::duration<const T, P>Section: 30.5.1 [time.duration.general] Status: New Submitter: Jonathan Wakely Opened: 2025-11-26 Last modified: 2025-11-26
Priority: Not Prioritized
View all issues with New status.
Discussion:
Using a const type as the rep for a chrono::duration causes various problems
but there seems to be no rule preventing it.
The non-const member operators that modify a duration don't work if
the rep type is const, e.g.
duration<const int>::operator++()
is typically ill-formed (unless the implementation chooses to store
remove_cv_t<rep> as the data member).
hash<duration<const int>> uses
hash<const int> which is not enabled,
so you can't hash a duration with a const rep.
Generic code that wants to perform arithmetic with the rep type
would need to remember to consistently use remove_cv_t<rep>
to work correctly with const types.
We should just disallow const rep types.
If you want a non-modifiable duration,
use const duration<R,P>
not duration<const R, P>
Proposed resolution:
This wording is relative to N5014.
Modify 30.5.1 [time.duration.general] as indicated:
-2-
Repshall be an arithmetic type or a class emulating an arithmetic type. Ifdurationis instantiated with adurationtypeas the argument for the template parameterRep, the program is ill-formed.-3- If
Periodis not a specialization ofratio, the program is ill-formed. IfPeriod::numis not positive, the program is ill-formed.-4- Members of
durationdo not throw exceptions other than those thrown by the indicated operations on their representations.