weekday_indexed class

Combines a weekday, representing a day of the week in the Gregorian calendar, with an index in the range [1, 5] that represents the weekday of the month (1st, 2nd, 3rd, and so on).


class weekday_indexed; // C++20


weekday_indexed is a trivially copyable and standard-layout class type.


Name Description
Constructors Construct a weekday_indexed with the specified weekday and value.
ok Check if the weekday value is valid.
weekday Get the weekday value.


Name Description
operator== Determine whether two weekday_indexed instances are equal.
operator<< Output a weekday_indexed to the specified stream.


Header: <chrono> Since C++ 20

Namespace: std::chrono

Compiler Option: /std:c++latest


Constructs a weekday_indexed initialized with a weekday value and an index.

constexpr weekday_indexed(const chrono::weekday& wd, unsigned index) noexcept; // C++20


The weekday value for the created weekday_indexed class.

The weekday of the month that the weekday lands on. It is in the range [1, 5]. For example, 2 indicates that the weekday lands on the second week of the month.

Example: Create a weekday_indexed

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
   constexpr auto wdi = weekday_indexed{Monday, 1};
   constexpr auto wdi2 = Monday[1];

    std::cout << wdi << ", " << wdi2;
    return 0;
Mon[1], Mon[1]


Check if the value stored in this weekday_indexed is in the valid range.

constexpr bool ok() const noexcept;

Return value

true if the week weekday value is in the valid range. Otherwise, false.


Get the weekday value.

constexpr chrono::weekday weekday() const noexcept;

Return value

The weekday value.


// compile using: /std:c++latest
#include <iostream>
#include <chrono>

int main()
    constexpr auto wdi = weekday_indexed{ Monday, 1 };
	std::cout << wdi << "\n";

    return 0;

See also

weekday class
weekday_last class
Header Files Reference