std::chrono::month_weekday::ok

来自cppreference.com
 
 
 
 
constexpr bool ok() const noexcept;
(C++20 起)

检查所含的 monthweekday_indexed 对象是否均合法。

返回值

month().ok() && weekday_indexed().ok()

示例

#include <cassert>
#include <chrono>
 
int main()
{
    auto mwdi{std::chrono::March/std::chrono::Friday[1]};
    assert(mwdi.ok());
 
    mwdi = {std::chrono::month(17)/std::chrono::Friday[1]}; 
    assert(not mwdi.ok());
 
    mwdi = {std::chrono::March/std::chrono::Friday[-4]}; 
    assert(not mwdi.ok());
}