std::chrono::duration<Rep,Period>::operator++, std::chrono::duration<Rep,Period>::operator--
来自 cppreference.cn
duration& operator++(); |
(1) | (C++11 起) (自 C++17 起为 constexpr) |
duration operator++( int ); |
(2) | (C++11 起) (自 C++17 起为 constexpr) |
duration& operator--(); |
(3) | (C++11 起) (自 C++17 起为 constexpr) |
duration operator--( int ); |
(4) | (C++11 起) (自 C++17 起为 constexpr) |
增加或减少此 duration 的 tick 数量。
如果 rep_
是一个成员变量,用于保存 duration 对象中的 tick 数量,
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
[编辑] 参阅
实现两个 duration 之间的复合赋值 (public 成员函数) | |
实现以持续时间为参数的算术运算 (函数模板) |