Namespaces
Variants
Views
Actions

std::chrono::weekday::operator[]

From cppreference.com
< cpp‎ | chrono‎ | weekday
 
 
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 std::chrono::weekday_indexed
    operator[]( unsigned index ) const noexcept;
(1) (since C++20)
constexpr std::chrono::weekday_last
    operator[]( std::chrono::last_spec ) const noexcept;
(2) (since C++20)
1) Constructs a weekday_indexed from *this and index. The result represents the index-th weekday in some yet-to-be-specified month. If index is not in the range [07] or if !ok() the values (an underlying weekday and an index) held in the result are unspecified.
2) Constructs a weekday_last from *this. The result represents the last weekday in some yet-to-be-specified month.

[edit] Return value

[edit] Example

#include <chrono>
#include <iostream>
using namespace std::chrono;
 
int main()
{
    constexpr auto second_tuesday_in_October_2019 =
        year_month_day{Tuesday[2] / October / 2019y};
 
    constexpr auto last_tuesday_in_October_2019 =
        year_month_day{Tuesday[last] / October / 2019y};
 
    std::cout << second_tuesday_in_October_2019 << '\n'
              << last_tuesday_in_October_2019 << '\n'; 
}

Possible output:

2019-10-08
2019-10-29