Created on 2009-07-06.00:00:00 last changed 162 months ago
[ Note - this edit already seems assumed by definition of the duration static members zero/min/max. They cannot meaningfully be constexpr without this change. ]
Proposed resolution:
Add constexpr to declaration of following functions and constructors:
Modify p1 [time], and the prototype definitions in [time.duration.nonmember], [time.duration.comparisons], and [time.duration.cast]:
Header <chrono> synopsis
// duration arithmetic template <class Rep1, class Period1, class Rep2, class Period2> typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type constexpr operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); template <class Rep1, class Period1, class Rep2, class Period2> typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type constexpr operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); template <class Rep1, class Period, class Rep2> duration<typename common_type<Rep1, Rep2>::type, Period> constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s); template <class Rep1, class Period, class Rep2> duration<typename common_type<Rep1, Rep2>::type, Period> constexpr operator*(const Rep1& s, const duration<Rep2, Period>& d); template <class Rep1, class Period, class Rep2> duration<typename common_type<Rep1, Rep2>::type, Period> constexpr operator/(const duration<Rep1, Period>& d, const Rep2& s); template <class Rep1, class Period1, class Rep2, class Period2> typename common_type<Rep1, Rep2>::type constexpr operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); // duration comparisons template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); // duration_cast template <class ToDuration, class Rep, class Period> constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
Change [time.duration]:
template <class Rep, class Period = ratio<1>> class duration { ... public: ... constexpr duration(const duration&) = default; ... };
[ Adopted at 2010-11 Batavia. ]
[ 2010 Rapperswil: ]
This issue was the motivation for Core adding the facility for constexpr functions to take parameters by const &. Move to Tentatively Ready.
[ 2010-03-15 Alisdair updated wording to be consistent with N3078. ]
[ 2009-10-30 Alisdair adds: ]
I suggest this issue moves from New to Open.
Half of this issue was dealt with in paper n2994 on constexpr constructors.
The other half (duration arithmetic) is on hold pending Core support for const & in constexpr functions.
[ 2009-09-21 Daniel adds: ]
An alternative (and possibly preferable solution for potentially heap-allocating big_int representation types) would be to ask the core language to allow references to const literal types as feasible arguments for constexpr functions.
The duration types in [time.duration] are exactly the sort of type that should be "literal types" in the new standard. Likewise, arithmetic operations on durations should be declared constexpr.
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-08-23 20:07:26 | admin | set | status: wp -> c++11 |
2010-11-29 10:49:30 | admin | set | messages: + msg5447 |
2010-11-14 13:10:57 | admin | set | status: voting -> wp |
2010-11-08 14:14:39 | admin | set | status: ready -> voting |
2010-10-21 19:00:35 | admin | set | messages: + msg4747 |
2010-10-21 19:00:35 | admin | set | status: open -> ready |
2010-10-21 18:28:33 | admin | set | messages: + msg1008 |
2010-10-21 18:28:33 | admin | set | messages: + msg1007 |
2010-10-21 18:28:33 | admin | set | messages: + msg1006 |
2010-10-21 18:28:33 | admin | set | messages: + msg1005 |
2010-10-21 18:28:33 | admin | set | messages: + msg1004 |
2009-07-06 00:00:00 | admin | create |