Title
duration types should be literal
Status
c++11
Section
[time.duration]
Submitter
Alisdair Meredith

Created on 2009-07-06.00:00:00 last changed 162 months ago

Messages

Date: 2010-11-29.10:49:30

[ Note - this edit already seems assumed by definition of the duration static members zero/min/max. They cannot meaningfully be constexpr without this change. ]

Date: 2010-11-29.10:49:30

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;
  ...

};
Date: 2010-11-29.10:49:30

[ Adopted at 2010-11 Batavia. ]

Date: 2010-10-21.19:00:35

[ 2010 Rapperswil: ]

This issue was the motivation for Core adding the facility for constexpr functions to take parameters by const &. Move to Tentatively Ready.

Date: 2010-03-15.00:00:00

[ 2010-03-15 Alisdair updated wording to be consistent with N3078. ]

Date: 2009-10-30.00:00:00

[ 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.

Date: 2009-09-21.00:00:00

[ 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.

Date: 2009-07-06.00:00:00

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:26adminsetstatus: wp -> c++11
2010-11-29 10:49:30adminsetmessages: + msg5447
2010-11-14 13:10:57adminsetstatus: voting -> wp
2010-11-08 14:14:39adminsetstatus: ready -> voting
2010-10-21 19:00:35adminsetmessages: + msg4747
2010-10-21 19:00:35adminsetstatus: open -> ready
2010-10-21 18:28:33adminsetmessages: + msg1008
2010-10-21 18:28:33adminsetmessages: + msg1007
2010-10-21 18:28:33adminsetmessages: + msg1006
2010-10-21 18:28:33adminsetmessages: + msg1005
2010-10-21 18:28:33adminsetmessages: + msg1004
2009-07-06 00:00:00admincreate