std::chrono::duration::operators (unary)
Std::Time::工期:运算符+%28一元%29,std::timeo::time::Operator-%28一元%29
| (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) |
为持续时间实现一元加和一元减。
如果rep_
是一个成员变量,该变量保存持续时间对象中的滴答数,以及D
是返回类型,
1%29相当于return D(*this
2%29相当于return D(-rep_
参数
%280%29
返回值
1%29此工期对象的副本
2%29这个持续时间对象的副本,并否定了滴答数。
例
二次
#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
二次
另见
operator++operator++(int)operator--operator--(int) | increments or decrements the tick count (public member function) |
---|---|
operator+operator-operator*operator/operator% | implements arithmetic operations with durations as arguments (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。