Files
2025-10-25 03:02:53 +03:00

4.0 KiB

[time.cal.wdidx]

30 Time library [time]

30.8 The civil calendar [time.cal]

30.8.7 Class weekday_indexed [time.cal.wdidx]

30.8.7.1 Overview [time.cal.wdidx.overview]

namespace std::chrono {class weekday_indexed { chrono::weekday wd_; // exposition onlyunsigned char index_; // exposition onlypublic: 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

#

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.

2

#

[Note 1:

A weekday_indexed object can be constructed by indexing a weekday with an unsigned.

— end note]

[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

#

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

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

🔗

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

1

#

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;

2

#

Returns: wd_.

🔗

constexpr unsigned index() const noexcept;

3

#

Returns: index_.

🔗

constexpr bool ok() const noexcept;

4

#

Returns: wd_.ok() && 1 <= index_ && index_ <= 5.

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

🔗

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

1

#

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);

2

#

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