命名空间
变体
操作

std::chrono::month::operator++, std::chrono::month::operator--

来自 cppreference.cn
< cpp‎ | chrono‎ | month
 
 
 
 
constexpr std::chrono::month& operator++() noexcept;
(1) (自 C++20 起)
constexpr std::chrono::month operator++( int ) noexcept;
(2) (自 C++20 起)
constexpr std::chrono::month& operator--() noexcept;
(3) (自 C++20 起)
constexpr std::chrono::month operator--( int ) noexcept;
(4) (自 C++20 起)

从月份值加或减 1,并将结果模 12 约简为范围 [112] 中的整数。

1,2) 执行 *this += std::chrono::months{1};
3,4) 执行 *this -= std::chrono::months{1};

内容

[编辑] 参数

(无)

[编辑] 返回值

1,3) 修改后对此 month 的引用。
2,4) 修改前创建的 month 的副本。

[编辑] 注释

调用这些函数之一后,ok() 始终为 true

[编辑] 示例

#include <cassert>
#include <chrono>
#include <iostream>
 
int main()
{
    std::chrono::month m{6};
 
    ++m;
    assert(m == std::chrono::month(7));
 
    --m;
    assert(m == std::chrono::month(6));
 
    m = std::chrono::December;
    m++; // rounds up to January
    assert(m.ok());
    std::cout << unsigned(m) << '\n';
 
    m = std::chrono::January;
    m--; // rounds down to December
    assert(m.ok());
    std::cout << unsigned(m) << '\n';
}

输出

1
12

[编辑] 参见

添加或减去数个月份
(公共成员函数) [编辑]
month 执行算术运算
(函数) [编辑]