std::chrono::year_month_weekday::ok
來自 cppreference.com
< cpp | chrono | year month weekday
constexpr bool ok() const noexcept; |
(C++20 起) | |
檢查此 year_month_weekday
物件是否表示有效日期。
[編輯] 返回值
true 如果此 year_month_weekday
物件表示有效日期,即 year().ok() && month().ok() && weekday_indexed().ok() 為 true 並且指定年和月至少有 index()
個 weekday()
。否則為 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()); }