Namespaces
Variants

std::chrono::year_month:: ok

From cppreference.net
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());
}