std::chrono::weekday::operator+=, std::chrono::weekday::operator-=
来自 cppreference.com
constexpr std::chrono::weekday& operator+=( const std::chrono::days& d ) noexcept; |
(1) | (自 C++20 起) |
constexpr std::chrono::weekday& operator-=( const std::chrono::days& d ) noexcept; |
(2) | (自 C++20 起) |
从星期值中添加或减去 d.count(),将结果模 7 减少为范围内的整数 [
0,
6]
。
1) 执行 *this = *this + d;.
2) 执行 *this = *this - d;.
内容 |
[编辑] 返回值
修改后此 weekday
的引用。
[编辑] 备注
在调用这些函数之一后,如果操作期间没有发生溢出,则 ok() 始终为真。
[编辑] 示例
运行此代码
#include <chrono> #include <iostream> int main() { std::cout << std::boolalpha; std::chrono::weekday wd{5}; // Friday is 5 wd += std::chrono::days(2); std::cout << (wd == std::chrono::weekday(0)) << ' ' << (wd == std::chrono::Sunday) << ' '; wd -= std::chrono::days(3); std::cout << (wd == std::chrono::weekday(4)) << ' ' << (wd == std::chrono::Thursday) << ' '; wd = std::chrono::Wednesday; wd += std::chrono::days{8}; // ((3 += 8 == 11) % 7) == 4; std::cout << (wd == std::chrono::Thursday) << ' '; wd -= (std::chrono::Sunday - std::chrono::Tuesday); // -= -2 // (4 -= -2) == 6 std::cout << (wd == std::chrono::Saturday) << '\n'; }
输出
true true true true true true
[编辑] 参见
递增或递减星期 (公有成员函数) | |
(C++20) |
对 weekday 进行算术运算(函数) |