Title
time_point constructors need to be constexpr
Status
resolved
Section
[time.point]
Submitter
Anthony Williams

Created on 2011-05-13.00:00:00 last changed 147 months ago

Messages

Date: 2012-11-07.13:15:52

Proposed resolution:

This wording is relative to the FDIS.

  1. Alter the class template definition in [time.point] as follows:

    template <class Clock, class Duration = typename Clock::duration>
    class time_point {
      […]
    public:
      // 20.11.6.1, construct:
      constexpr time_point(); // has value epoch
      constexpr explicit time_point(const duration& d); // same as time_point() + d
      template <class Duration2>
        constexpr time_point(const time_point<clock, Duration2>& t);
    
      // 20.11.6.2, observer:
      constexpr duration time_since_epoch() const;
      […]
    };
    
  2. Alter the declarations in [time.point.cons]:

    constexpr time_point();
    

    -1- Effects: Constructs an object of type time_point, initializing d_ with duration::zero(). Such a time_point object represents the epoch.

    constexpr explicit time_point(const duration& d);
    

    -2- Effects: Constructs an object of type time_point, initializing d_ with d. Such a time_point object represents the epoch + d.

    template <class Duration2>
      constexpr time_point(const time_point<clock, Duration2>& t);
    

    -3- Remarks: This constructor shall not participate in overload resolution unless Duration2 is implicitly convertible to duration.

    -4- Effects: Constructs an object of type time_point, initializing d_ with t.time_since_epoch().

  3. Alter the declaration in [time.point.observer]:

    constexpr duration time_since_epoch() const;
    

    -1- Returns: d_.

Date: 2012-11-07.13:15:52

[ 2012, Portland ]

Resolved by adopting paper n3469.

Date: 2011-05-13.00:00:00

In [time.point], time_point::min() and time_point::max() are listed as constexpr. However, time_point has no constexpr constructors, so is not a literal type, and so these functions cannot be constexpr without adding a constexpr constructor for implementation purposes.

Proposed resolution: Add constexpr to the constructors of time_point. The effects of the constructor template basically imply that the member function time_since_epoch() is intended to be constexpr as well.

History
Date User Action Args
2012-11-07 13:15:52adminsetmessages: + msg6274
2012-11-07 13:15:52adminsetstatus: open -> resolved
2011-08-16 10:45:53adminsetstatus: new -> open
2011-05-17 22:23:06adminsetmessages: + msg5776
2011-05-13 00:00:00admincreate