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// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_CHRONO_WEEKDAY_INDEXED_HPP
5#define TETL_CHRONO_WEEKDAY_INDEXED_HPP
6
7#include <etl/_chrono/weekday.hpp>
8
9namespace etl::chrono {
10
11/// \ingroup chrono
13 weekday_indexed() = default;
14
15 constexpr weekday_indexed(etl::chrono::weekday const& wd, unsigned index) noexcept
16 : _wd{wd}
17 , _index{static_cast<etl::uint8_t>(index)}
18 {
19 }
20
21 [[nodiscard]] constexpr auto weekday() const noexcept -> etl::chrono::weekday
22 {
23 return _wd;
24 }
25
26 [[nodiscard]] constexpr auto index() const noexcept -> unsigned
27 {
28 return _index;
29 }
30
31 [[nodiscard]] constexpr auto ok() const noexcept -> bool
32 {
33 return weekday().ok() and ((_index >= 1) and (_index <= 5));
34 }
35
36 friend constexpr auto operator==(weekday_indexed const& lhs, weekday_indexed const& rhs) noexcept -> bool
37 {
38 return lhs.weekday() == rhs.weekday() and lhs.index() == rhs.index();
39 }
40
41private:
42 etl::chrono::weekday _wd;
43 etl::uint8_t _index;
44};
45
46constexpr auto weekday::operator[](unsigned index) const noexcept -> weekday_indexed
47{
48 return {*this, index};
49}
50
51} // namespace etl::chrono
52
53#endif // TETL_CHRONO_WEEKDAY_INDEXED_HPP
Definition abs.hpp:12
Definition adjacent_find.hpp:9
Definition weekday_indexed.hpp:12
constexpr auto index() const noexcept -> unsigned
Definition weekday_indexed.hpp:26
constexpr auto ok() const noexcept -> bool
Definition weekday_indexed.hpp:31
constexpr auto weekday() const noexcept -> etl::chrono::weekday
Definition weekday_indexed.hpp:21
constexpr weekday_indexed(etl::chrono::weekday const &wd, unsigned index) noexcept
Definition weekday_indexed.hpp:15
friend constexpr auto operator==(weekday_indexed const &lhs, weekday_indexed const &rhs) noexcept -> bool
Definition weekday_indexed.hpp:36
Definition weekday.hpp:19
constexpr auto ok() const noexcept -> bool
Definition weekday.hpp:81
constexpr auto operator[](unsigned index) const noexcept -> weekday_indexed
Definition weekday_indexed.hpp:46
friend constexpr auto operator==(weekday const &lhs, weekday const &rhs) noexcept -> bool
Definition weekday.hpp:92