命名空间
变体
操作

std::chrono::year_month::ok

来自 cppreference.cn
< cpp‎ | chrono‎ | year month
 
 
 
 
constexpr bool ok() const noexcept;
(自 C++20 起)

检查存储在此对象中的年份和月份值是否有效。

[编辑] 返回值

year().ok() && month().ok()

[编辑] 示例

#include <chrono>
using namespace std::chrono_literals;
 
int main()
{
    constexpr std::chrono::year_month ym1{3030y, std::chrono::July};
    static_assert(ym1.ok());
 
    constexpr std::chrono::year_month ym2{std::chrono::year(2020)/16};
    static_assert(!ym2.ok());
}