命名空间
变体
操作

std::chrono::last_spec, std::chrono::last

来自 cppreference.cn
< cpp‎ | chrono
 
 
 
定义于头文件 <chrono>
struct last_spec

{
    explicit last_spec() = default;

};
(自 C++20 起)
inline constexpr last_spec last{};
(自 C++20 起)

last_spec 是一个空标签类型,与其他日历类型结合使用,以指示序列中的最后一个事物。根据上下文,它可以指示一个月中的最后一天(如 2018y/February/last,表示 2018 年 2 月的最后一天,即 2018-02-28)或一个月中一周的最后一天(如 2018/February/Sunday[last],表示 2018 年 2 月的最后一个星期日,即 2018-02-25)。

[编辑] 示例

#include <chrono>
 
int main()
{
    using namespace std::chrono;
 
    constexpr auto mdl {June/last};
    static_assert(mdl == month_day_last(month(6)));
 
    constexpr auto ymwdl {year(2023)/December/Tuesday[last]};
    static_assert(ymwdl ==
        year_month_weekday_last(year(2023), month(12), weekday_last(Tuesday)));
}