Namespaces
Variants
Views
Actions

std::chrono::last_spec

From cppreference.com
< cpp‎ | chrono
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
Date and time utilities
(C++11)
(C++11)
Time of day
(C++20)



(C++20)(C++20)(C++20)(C++20)
Clocks
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Calendars
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Time zones
(C++20)
(C++20)
(C++20)
(C++20)
C-style date and time
 
Defined in header <chrono>
struct last_spec

{
    explicit last_spec() = default;

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

last_spec is an empty tag type that is used in conjunction with other calendar types to indicate the last thing in a sequence. Depending on context, it may indicate the last day of a month (as in 2018y/February/last, for last day of February 2018, i.e., 2018-02-28) or the last day of the week in a month (as in 2018/February/Sunday[last], for last Sunday of February 2018, i.e., 2018-02-25).

[edit] Example

#include <iostream>
#include <chrono>
 
int main()
{
    std::cout << std::boolalpha;
 
    constexpr auto mdl {std::chrono::June/std::chrono::last};
    std::cout << (mdl == std::chrono::month_day_last(std::chrono::month(6))) << ' ';
 
    constexpr auto ymwdl {std::chrono::year(2023)/
                          std::chrono::December/
                          std::chrono::Tuesday[std::chrono::last]
                         };
    std::cout << (ymwdl == std::chrono::year_month_weekday_last(
                           std::chrono::year(2023), 
                           std::chrono::month(12),
                           std::chrono::weekday_last(std::chrono::Tuesday))
                           ) << '\n';
}

Output:

true true