名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | chrono
 
 
日期和時間庫
時間點
(C++11)
(C++20)
時長
(C++11)
時鐘
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
日間時間
(C++20)(C++20)
(C++20)(C++20)
(C++20)
日曆
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
last_speclast
(C++20)(C++20)
chrono I/O
(C++20)

 
定義於標頭檔案 <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)));
}