Namespaces
Variants
Views
Actions

std::chrono::weekday_last::weekday_last

From cppreference.com
< cpp‎ | chrono‎ | weekday last
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
(C++26)
Three-way comparison
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(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++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)

 
 
 
constexpr explicit weekday_last( const std::chrono::weekday& wd ) noexcept;
(since C++20)

Constructs a weekday_last object storing the weekday wd.

[edit] Notes

A more convenient way to construct a weekday_last is with weekday's operator[], i.e., wd[std::chrono::last].

[edit] Example

#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';
}

Possible output:

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