last_spec 结构

指示一个月内的最后一项。 例如,一个月的最后一个星期几,例如 2020 年 2 月的最后一个星期二。 或者一个月的最后一天,例如 2019 年 4 月的最后一天。

语法

struct last_spec; // C++20
inline constexpr last_spec last{} // C++20

示例: last

使用 last_spec 来指示一个月内的最后一项。 下面的示例使用 last 来指示:

  • 12 月的最后一天为 monthDayLast
  • 2021 年 7 月的最后一个星期五为 year_month_weekday_last
  • 1975 年 4 月的最后一天为 year_month_day_last
// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    constexpr auto monthDayLast{December/last}; // 'last' resolves to last_spec
    std::cout << monthDayLast << '\n';

    constexpr auto yearMonthWeekDayLast{year(2021)/July/Friday[last]}; // 'last' resolves to last_spec
    std::cout << yearMonthWeekDayLast << '\n';

    constexpr auto yearMonthDayLast{ April / last / 1975 };
    std::cout << yearMonthDayLast << "\n";  

    return 0;
}
Dec/last
2021/Jul/Fri[last]
1975/Apr/last

成员

名称 描述
构造函数 构造 last_spec

要求

标头: <chrono> (自C++20以来)

命名空间std::chrono

编译器选项: /std:c++latest

构造函数

构造 last_spec

explicit last_spec() = default;

备注

通常不会直接创建 last_spec 实例。 将使用 last,如上面的示例 last 所示。

另请参阅

<chrono>
month_day_last
month_weekday_last
头文件引用