Skip to content

Search topics & cppreference

Search all study topics, concept maps, and 6,587 C++ and C reference pages.

std::chrono::month_weekday::ok

Checks if the contained month and weekday_indexed objects are valid.

NotebookLM
constexpr bool ok() const noexcept;
(since C++20)

Checks if the contained month and weekday_indexed objects are valid.

Return value

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

Example

example.cpp
#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());
}

Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.