std::chrono::weekday::ok
来自 cppreference.com
constexpr bool ok() const noexcept; |
(自 C++20 起) | |
检查存储在 *this 中的星期几值是否在有效范围内,即 [
0,
6]
。
[编辑] 返回值
如果存储在 *this 中的星期几值在范围内 [
0,
6]
,则返回 true。否则返回 false。
[编辑] 示例
运行此代码
#include <chrono> #include <iomanip> #include <iostream> #include <locale> #include <string> struct weekday_ok : std::numpunct<char> { std::string do_truename() const override { return " (is valid weekday)"; } std::string do_falsename() const override { return " (is not valid weekday)"; } }; int main() { std::cout.imbue(std::locale(std::cout.getloc(), new weekday_ok)); std::cout << std::boolalpha; for (const unsigned u : {0 /* Sun */, 1 /* Mon */, 6, 7 /* Sun */, 8, 9}) { const std::chrono::weekday wd{u}; std::cout << "u: " << u << "; wd: " << wd.c_encoding() << wd.ok() << '\n'; } }
输出
u: 0; wd: 0 (is valid weekday) u: 1; wd: 1 (is valid weekday) u: 6; wd: 6 (is valid weekday) u: 7; wd: 0 (is valid weekday) u: 8; wd: 8 (is not valid weekday) u: 9; wd: 9 (is not valid weekday)
[编辑] 另请参阅
检索存储的星期几值 检索 ISO 8601 星期几值 (公有成员函数) |