27 Time library [time]

27.8 The civil calendar [time.cal]

27.8.7 Class weekday_­indexed [time.cal.wdidx]

27.8.7.1 Overview [time.cal.wdidx.overview]

namespace std::chrono {
  class weekday_indexed {
    chrono::weekday  wd_;       // exposition only
    unsigned char    index_;    // exposition only

  public:
    weekday_indexed() = default;
    constexpr weekday_indexed(const chrono::weekday& wd, unsigned index) noexcept;

    constexpr chrono::weekday weekday() const noexcept;
    constexpr unsigned        index()   const noexcept;
    constexpr bool ok() const noexcept;
  };
}
weekday_­indexed represents a weekday and a small index in the range 1 to 5.
This class is used to represent the first, second, third, fourth, or fifth weekday of a month.
Note
:
A weekday_­indexed object can be constructed by indexing a weekday with an unsigned.
— end note
 ]
Example
:
constexpr auto wdi = Sunday[2]; // wdi is the second Sunday of an as yet unspecified month
static_assert(wdi.weekday() == Sunday);
static_assert(wdi.index() == 2);
— end example
 ]
weekday_­indexed is a trivially copyable and standard-layout class type.

27.8.7.2 Member functions [time.cal.wdidx.members]

constexpr weekday_indexed(const chrono::weekday& wd, unsigned index) noexcept;
Effects: Initializes wd_­ with wd and index_­ with index.
The values held are unspecified if !wd.ok() or index is not in the range [0, 7].
constexpr chrono::weekday weekday() const noexcept;
Returns: wd_­.
constexpr unsigned index() const noexcept;
Returns: index_­.
constexpr bool ok() const noexcept;
Returns: wd_­.ok() && 1 <= index_­ && index_­ <= 5.

27.8.7.3 Non-member functions [time.cal.wdidx.nonmembers]

constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
Returns: x.weekday() == y.weekday() && x.index() == y.index().
template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi);
Effects: Equivalent to:
auto i = wdi.index();
return os << (i >= 1 && i <= 5 ?
  format(os.getloc(), STATICALLY-WIDEN<charT>("{}[{}]"), wdi.weekday(), i) :
  format(os.getloc(), STATICALLY-WIDEN<charT>("{}[{} is not a valid index]"),
         wdi.weekday(), i));