std::chrono::year_month_weekday::ok

来自cppreference.com
 
 
 
 
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());
}