Namespaces
Variants

std::chrono::year_month_weekday:: ok

From cppreference.net
constexpr bool ok ( ) const noexcept ;
(自 C++20 起)

检查此 year_month_weekday 对象是否表示有效日期。

返回值

若此 year_month_weekday 对象表示有效日期,即 year ( ) . ok ( ) && month ( ) . ok ( ) && weekday_indexed ( ) . ok ( ) true ,且在指定年份和月份中至少存在 index() weekday() ,则返回 true ;否则返回 false

示例

#include <cassert>
#include <chrono>
int main()
{
    auto ymwdi{std::chrono::Wednesday[1]/1/2021};
    assert(ymwdi.ok());
    ymwdi = std::chrono::year(2021)/std::chrono::month(1)/std::chrono::Wednesday[42];
    assert(!ymwdi.ok());
}