tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
weekday_indexed.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CHRONO_WEEKDAY_INDEXED_HPP
4#define TETL_CHRONO_WEEKDAY_INDEXED_HPP
5
7
8namespace etl::chrono {
9
12 weekday_indexed() = default;
13
14 constexpr weekday_indexed(etl::chrono::weekday const& wd, unsigned index) noexcept
15 : _wd{wd}
16 , _index{static_cast<etl::uint8_t>(index)}
17 {
18 }
19
20 [[nodiscard]] constexpr auto weekday() const noexcept -> etl::chrono::weekday { return _wd; }
21
22 [[nodiscard]] constexpr auto index() const noexcept -> unsigned { return _index; }
23
24 [[nodiscard]] constexpr auto ok() const noexcept -> bool
25 {
26 return weekday().ok() and ((_index >= 1) and (_index <= 5));
27 }
28
29 friend constexpr auto operator==(weekday_indexed const& lhs, weekday_indexed const& rhs) noexcept -> bool
30 {
31 return lhs.weekday() == rhs.weekday() and lhs.index() == rhs.index();
32 }
33
34private:
36 etl::uint8_t _index;
37};
38
39constexpr auto weekday::operator[](unsigned index) const noexcept -> weekday_indexed { return {*this, index}; }
40
41} // namespace etl::chrono
42
43#endif // TETL_CHRONO_WEEKDAY_INDEXED_HPP
Definition abs.hpp:11
Definition adjacent_find.hpp:8
TETL_BUILTIN_UINT8 uint8_t
Unsigned integer type with width of exactly 8 bits.
Definition uint_t.hpp:11
Definition weekday_indexed.hpp:11
constexpr auto index() const noexcept -> unsigned
Definition weekday_indexed.hpp:22
constexpr auto ok() const noexcept -> bool
Definition weekday_indexed.hpp:24
constexpr auto weekday() const noexcept -> etl::chrono::weekday
Definition weekday_indexed.hpp:20
constexpr weekday_indexed(etl::chrono::weekday const &wd, unsigned index) noexcept
Definition weekday_indexed.hpp:14
friend constexpr auto operator==(weekday_indexed const &lhs, weekday_indexed const &rhs) noexcept -> bool
Definition weekday_indexed.hpp:29
Definition weekday.hpp:18
constexpr auto operator[](unsigned index) const noexcept -> weekday_indexed
Definition weekday_indexed.hpp:39