std::chrono::year_month:: ok
From cppreference.net
<
cpp
|
chrono
|
year month
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::year_month
| Member functions | ||||
|
year_month::ok
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
(C++26)
|
|
constexpr
bool
ok
(
)
const
noexcept
;
|
(自 C++20 起) | |
检查此对象中存储的年份和月份值是否有效。
返回值
year ( ) . ok ( ) && month ( ) . ok ( )
示例
运行此代码
#include <chrono> using namespace std::chrono_literals; int main() { constexpr std::chrono::year_month ym1{3030y, std::chrono::July}; static_assert(ym1.ok()); constexpr std::chrono::year_month ym2{std::chrono::year(2020)/16}; static_assert(!ym2.ok()); }