std::chrono::duration<Rep,Period>::operator+(unary), std::chrono::duration<Rep,Period>::operator-(unary)
来自cppreference.com
工具库
日期和时间工具
时间点 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时长 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时钟 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当天时刻 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
日历 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时区 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono I/O |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C 风格日期和时间 |
std::chrono::duration
成员函数 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
非成员函数 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
辅助类 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(1) | ||
constexpr
duration operator+() const;
|
(C++17 前) | |
constexpr std::common_type_t<duration>
operator+() const;
|
(C++17 起) | |
(2) | ||
constexpr
duration operator-() const;
|
(C++17 前) | |
constexpr std::common_type_t<duration>
operator-() const;
|
(C++17 起) | |
实现 duration 的一元加和一元减。
若 rep_
为 duration 对象中保有计次数的成员变量,而 D
是返回类型,则
1) 等价于 return D(*this);
2) 等价于 return D(-rep_);
参数
(无)
返回值
1) 此 duration 对象的副本
2) 此 duration 对象的副本,对其计次数取反
示例
运行此代码
#include <chrono> #include <iostream> int main() { std::chrono::seconds s1(10); std::chrono::seconds s2 = -s1; std::cout << "negated 10 seconds are " << s2.count() << " seconds\n"; }
输出:
negated 10 seconds are -10 seconds
参阅
递增或递减滴答计数 (公开成员函数) |
|
实现以时长为实参的算术运算 (函数模板) |