[time.cal.wdidx]

# 30 Time library [[time]](./#time)

## 30.8 The civil calendar [[time.cal]](time.cal#wdidx)

### 30.8.7 Class weekday_indexed [time.cal.wdidx]

#### [30.8.7.1](#overview) Overview [[time.cal.wdidx.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; };}

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5286)

weekday_indexed represents a weekday and a small index in the range 1 to 5[.](#overview-1.sentence-1)

This class is used to represent the
first, second, third, fourth, or fifth weekday of a month[.](#overview-1.sentence-2)

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5292)

[*Note [1](#overview-note-1)*:

A weekday_indexed object
can be constructed by indexing a weekday with an unsigned[.](#overview-2.sentence-1)

â *end note*]

[*Example [1](#overview-example-1)*: constexpr auto wdi = Sunday[2]; // wdi is the second Sunday of an as yet unspecified monthstatic_assert(wdi.weekday() == Sunday);static_assert(wdi.index() == 2); â *end example*]

[3](#overview-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5306)

weekday_indexed is a trivially copyable and standard-layout class type[.](#overview-3.sentence-1)

#### [30.8.7.2](#members) Member functions [[time.cal.wdidx.members]](time.cal.wdidx.members)

[ð](#lib:weekday_indexed,constructor)

`constexpr weekday_indexed(const chrono::weekday& wd, unsigned index) noexcept;
`

[1](#members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5317)

*Effects*: Initializes wd_ with wd and index_ with index[.](#members-1.sentence-1)

The values held are unspecified if !wd.ok() or index is not in the range [0, 7][.](#members-1.sentence-2)

[ð](#lib:weekday,weekday_indexed)

`constexpr chrono::weekday weekday() const noexcept;
`

[2](#members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5329)

*Returns*: wd_[.](#members-2.sentence-1)

[ð](#lib:index,weekday_indexed)

`constexpr unsigned index() const noexcept;
`

[3](#members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5340)

*Returns*: index_[.](#members-3.sentence-1)

[ð](#lib:ok,weekday_indexed)

`constexpr bool ok() const noexcept;
`

[4](#members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5351)

*Returns*: wd_.ok() && 1 <= index_ && index_ <= 5[.](#members-4.sentence-1)

#### [30.8.7.3](#nonmembers) Non-member functions [[time.cal.wdidx.nonmembers]](time.cal.wdidx.nonmembers)

[ð](#lib:operator==,weekday_indexed)

`constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
`

[1](#nonmembers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5364)

*Returns*: x.weekday() == y.weekday() && x.index() == y.index()[.](#nonmembers-1.sentence-1)

[ð](#lib:operator%3c%3c,weekday_indexed)

`template<class charT, class traits>
  basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi);
`

[2](#nonmembers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5377)

*Effects*: Equivalent to:auto i = wdi.index();return os << (i >= 1 && i <= 5 ? format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L}[{}]"), wdi.weekday(), i) : format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L}[{} is not a valid index]"),
 wdi.weekday(), i));
