std::chrono::month_day:: ok
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
month_day::ok
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
(C++26)
|
|
constexpr
bool
ok
(
)
const
noexcept
;
|
(自 C++20 起) | |
确定此
month_day
是否存储有效的月-日组合。
当满足以下条件时组合是有效的:
month()
表示有效月份(
month
(
)
.
ok
(
)
==
true
),
unsigned
{
day
(
)
}
>=
1
,且
unsigned
{
day
(
)
}
<=
D
,其中 D 是由
month()
表示的月份中的天数。二月的天数被视为 29 天。
返回值
true 表示月份和日期组合有效,否则为 false。
示例
#include <chrono> #include <iostream> int main() { std::cout << std::boolalpha; constexpr auto md1{std::chrono::July/15}; std::cout << (md1.ok()) << ' '; constexpr std::chrono::month_day md2{std::chrono::month(14), std::chrono::day(42)}; std::cout << (md2.ok()) << ' '; constexpr auto md3{std::chrono::February/29}; std::cout << (md3.ok()) << '\n'; }
输出:
true false true