std::chrono::weekday_indexed::ok
来自cppreference.com
< cpp | chrono | weekday indexed
constexpr bool ok() const noexcept; |
(C++20 起) | |
检查存储于 *this 的 weekday 对象和索引是否均合法。
返回值
若 weekday().ok() == true 且 index() 在范围 [
1,
5]
中则为 true。否则为 false。
示例
运行此代码
#include <chrono> #include <iostream> int main() { std::cout << std::boolalpha; std::chrono::weekday_indexed wdi{std::chrono::Tuesday[2]}; std::cout << (wdi.ok()) << ' '; wdi = {std::chrono::weekday(42)[2]}; std::cout << (wdi.ok()) << ' '; wdi = {std::chrono::Tuesday[-4]}; std::cout << (wdi.ok()) << '\n'; }
输出:
true false false