std::chrono:: operator/ (calendar)
|
定义于头文件
<chrono>
|
||
year_month
|
||
|
constexpr
auto
operator
/
(
const
std::
chrono
::
year
&
y,
const
std::
chrono
::
month
&
m
)
noexcept
|
(1) | (C++20 起) |
|
constexpr
auto
operator
/
(
const
std::
chrono
::
year
&
y,
int
m
)
noexcept
- > std:: chrono :: year_month ; |
(2) | (C++20 起) |
month_day
|
||
|
constexpr
auto
operator
/
(
const
std::
chrono
::
month
&
m,
const
std::
chrono
::
day
&
d
)
noexcept
|
(3) | (C++20 起) |
|
constexpr
auto
operator
/
(
const
std::
chrono
::
month
&
m,
int
d
)
noexcept
- > std:: chrono :: month_day ; |
(4) | (C++20 起) |
|
constexpr
auto
operator
/
(
int
m,
const
std::
chrono
::
day
&
d
)
noexcept
- > std:: chrono :: month_day ; |
(5) | (C++20 起) |
|
constexpr
auto
operator
/
(
const
std::
chrono
::
day
&
d,
const
std::
chrono
::
month
&
m
)
noexcept
|
(6) | (C++20 起) |
|
constexpr
auto
operator
/
(
const
std::
chrono
::
day
&
d,
int
m
)
noexcept
- > std:: chrono :: month_day ; |
(7) | (C++20 起) |
month_day_last
|
||
|
constexpr
auto
operator
/
(
const
std::
chrono
::
month
&
m,
std::
chrono
::
last_spec
)
noexcept
|
(8) | (C++20 起) |
|
constexpr
auto
operator
/
(
int
m,
std::
chrono
::
last_spec
)
noexcept
- > std:: chrono :: month_day_last ; |
(9) | (C++20 起) |
|
constexpr
auto
operator
/
(
std::
chrono
::
last_spec
,
const
std::
chrono
::
month
&
m
)
noexcept
|
(10) | (C++20 起) |
|
constexpr
auto
operator
/
(
std::
chrono
::
last_spec
,
int
m
)
noexcept
- > std:: chrono :: month_day_last ; |
(11) | (C++20 起) |
month_weekday
|
||
|
constexpr
auto
operator
/
(
const
<span class="kw262
|
这些 operator / 重载为创建 公历溯推日历 日期提供了常规语法。
创建完整日期时,以下三种顺序均可接受:
-
年/月/日, -
月/日/年, -
日/月/年.
在每种情况下
day
可替换为以下选项之一:
- std::chrono::last ,表示该月的最后一天;
-
weekday [ i ],表示该月的第ith 个 weekday ; -
weekday [ std::chrono::last ],表示该月的最后一个 weekday 。
当普通整数的含义通过其他操作数的类型可以明确时,该整数可以被接受: 2005y / 4 / 5 是允许的,但 5 / April / 2005 则不允许。
部分日期类型(
year_month
、
month_day
等)可通过在三种顺序中不应用第二个
operator
/
来创建。
返回值
示例
#include <chrono> using namespace std::chrono; constexpr auto ym{2021y/8}; static_assert(ym == year_month(year(2021), August)); constexpr auto md{9/15d}; static_assert(md == month_day(September, day(15))); constexpr auto mdl{October/last}; static_assert(mdl == month_day_last(month(10))); constexpr auto mw{11/Monday[3]}; static_assert(mw == month_weekday(November, Monday[3])); constexpr auto mwdl{December/Sunday[last]}; static_assert(mwdl == month_weekday_last(month(12), weekday_last(Sunday))); // 这个星球及其他地方实际使用的三种年月日顺序: constexpr auto ymd{year(2021)/January/day(23)}; static_assert(ymd == month{1}/23/2021); static_assert(ymd == day{23}/1/2021); static_assert(ymd == year_month_day(2021y, month(January), 23d)); int main() {}