Namespaces
Variants

std::chrono::weekday_last:: weekday_last

From cppreference.net
constexpr explicit weekday_last ( const std:: chrono :: weekday & wd ) noexcept ;
(depuis C++20)

Construit un objet weekday_last stockant le weekday wd .

Notes

Une manière plus pratique de construire un weekday_last est d'utiliser l' weekday 's operator [ ] , c'est-à-dire, wd [ std:: chrono :: last ] .

Exemple

#include <chrono>
#include <iostream>
using namespace std::chrono;
int main()
{
    const year_month_day ymd{floor<days>(system_clock::now())};
    const weekday_last wdl{Sunday[last]}; // A last Sunday of a month
    const year_month_day last_sun{ymd.year() / ymd.month() / wdl};
    std::cout << "The last Sunday of current month falls on "
              << (int)last_sun.year() << '/'
              << (unsigned)last_sun.month() << '/'
              << (unsigned)last_sun.day() << '\n';
}

Sortie possible :

The last Sunday of current month falls on 2021/9/26