std::chrono::duration<Rep,Period>::operator+(一元), std::chrono::duration<Rep,Period>::operator-(一元)
来自 cppreference.cn
(1) | ||
constexpr duration operator+() const; |
(until C++17) | |
constexpr std::common_type_t<duration> operator+() const; |
(since C++17) | |
(2) | ||
constexpr duration operator-() const; |
(until C++17) | |
constexpr std::common_type_t<duration> operator-() const; |
(since C++17) | |
实现 duration 的一元加和一元减运算符。
如果 rep_ 是一个成员变量,用于保存 duration 对象中的滴答数,而 D 是返回类型,
1) 等价于 return D(*this);。
2) 等价于 return D(-rep_);。
目录 |
[编辑] 参数
(无)
[编辑] 返回值
1) 此 duration 对象的副本。
2) 此 duration 对象的副本,滴答数取反。
[编辑] 示例
运行此代码
#include <chrono> #include <iostream> int main() { constexpr std::chrono::seconds s1(-052); constexpr std::chrono::seconds s2 = -s1; std::cout << "Negated " << s1 << " are " << s2 << '\n'; }
输出
Negated -42s are 42s
[编辑] 参见
递增或递减滴答计数 (公共成员函数) | |
实现以 duration 为参数的算术运算 (函数模板) |