Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Appendix: Rationale

See N2661 - A Foundation to Sleep On which is very informative and provides motivation for key design decisions. This section contains some extracts from this document.

Why duration needs 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 boost::chrono::hours hours;
    typedef boost::chrono::minutes minutes;
    typedef boost::chrono::seconds seconds;
public:
    hours hours_;
    minutes minutes_;
    seconds seconds_;

    template <class Rep, class Period>
      explicit ClockTime(const boost::chrono::duration<Rep, Period>& d)
        : hours_  (boost::chrono::duration_cast<hours>  (d)),
          minutes_(boost::chrono::duration_cast<minutes>(d % hours(1))),
          seconds_(boost::chrono::duration_cast<seconds>(d % minutes(1)))
          {}
};

PrevUpHomeNext