Title
duration is missing operator%
Status
c++11
Section
[time.duration]
Submitter
Terry Golubiewski

Created on 2008-11-30.00:00:00 last changed 154 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Add to the synopsis in [time]:

template <class Rep1, class Period, class Rep2>
  duration<typename common_type<Rep1, Rep2>::type, Period>
  operator%(const duration<Rep1, Period>& d, const Rep2& s);
template <class Rep1, class Period1, class Rep2, class Period2>
  typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);

Add to the synopsis of duration in [time.duration]:

template <class Rep, class Period = ratio<1>>
class duration {
public:
  ...
  duration& operator%=(const rep& rhs);
  duration& operator%=(const duration& d);
  ...
};

Add to [time.duration.arithmetic]:

duration& operator%=(const rep& rhs);

Effects: rep_ %= rhs.

Returns: *this.

duration& operator%=(const duration& d);

Effects: rep_ %= d.count().

Returns: *this.

Add to [time.duration.nonmember]:

template <class Rep1, class Period, class Rep2>
  duration<typename common_type<Rep1, Rep2>::type, Period>
  operator%(const duration<Rep1, Period>& d, const Rep2& s);

Requires: Rep2 shall be implicitly convertible to CR(Rep1, Rep2) and Rep2 shall not be an instantiation of duration. Diagnostic required.

Returns: duration<CR, Period>(d) %= s.

template <class Rep1, class Period1, class Rep2, class Period2>
  typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);

Returns: common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type(lhs) %= rhs.

Date: 2010-10-21.18:28:33

[ 2009-07 Frankfurt: ]

Howard to open a separate issue (1177) to handle the removal of member functions from overload sets, provide wording, and possibly demonstrate how this can be implemented using enable_if (see 947).

Move to Ready.

Date: 2010-10-21.18:28:33

[ 2009-07 Frankfurt ]

Moved from Tentatively Ready to Open only because the wording needs to be improved for enable_if type constraining, possibly following Robert's formula.

Date: 2010-10-21.18:28:33

[ Batavia (2009-05): ]

We agree with the proposed resolution. Move to Tentatively Ready.

Date: 2010-10-21.18:28:33

[ Summit: ]

Agree except that there is a typo in the proposed resolution. The member operators should be operator%=.

Date: 2008-11-30.00:00:00

Addresses US 81

duration is missing operator%. This operator is convenient for computing where in a time frame a given duration lies. A motivating example is converting a duration into a "broken-down" time duration such as hours::minutes::seconds:

class ClockTime
{
    typedef std::chrono::hours hours;
    typedef std::chrono::minutes minutes;
    typedef std::chrono::seconds seconds;
public:
    hours hours_;
    minutes minutes_;
    seconds seconds_;

    template <class Rep, class Period>
      explicit ClockTime(const std::chrono::duration<Rep, Period>& d)
        : hours_  (std::chrono::duration_cast<hours>  (d)),
          minutes_(std::chrono::duration_cast<minutes>(d % hours(1))),
          seconds_(std::chrono::duration_cast<seconds>(d % minutes(1)))
          {}
};
History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg4447
2010-10-21 18:28:33adminsetmessages: + msg4446
2010-10-21 18:28:33adminsetmessages: + msg4445
2010-10-21 18:28:33adminsetmessages: + msg4444
2010-10-21 18:28:33adminsetmessages: + msg4443
2008-11-30 00:00:00admincreate