C++ 参考手册

位置:首页 > C++ 参考手册 >日期和时间工具 >std::chrono::duration > std::chrono::duration<Rep,Period>::operator++, std::chrono::duration<Rep,Period>::operator--

(1)
duration& operator++();
(C++17 前)
constexpr duration& operator++();
(C++17 起)
(2)
duration operator++(int);
(C++17 前)
constexpr duration operator++(int);
(C++17 起)
(3)
duration& operator--();
(C++17 前)
constexpr duration& operator--();
(C++17 起)
(4)
duration operator--(int);
(C++17 前)
constexpr duration operator--(int);
(C++17 起)

自增或自减此 duration 的计次数。

rep_ 是 duration 对象中保有计次数的成员变量,则

1) 等价于 ++rep_; return *this;
2) 等价于 return duration(rep_++)
3) 等价于 --rep_; return *this;
4) 等价于 return duration(rep_--);

参数

(无)

返回值

1,3) 到修改后的此 duration 的引用
2,4) 修改前所做的 duration 副本

示例

#include <chrono>
#include <iostream>
 
int main()
{
    std::chrono::hours h(1);
    std::chrono::minutes m = ++h;
    m--;
    std::cout << m.count() << " minutes\n";
}

输出:

119 minutes

参阅

实现二个时长间的复合赋值
(公开成员函数)
实现以时长为实参的算术运算
(函数模板)