| 107 | |
| 108 | template <typename E, detail::enum_subtype S = detail::subtype_v<E>> |
| 109 | [[nodiscard]] constexpr auto enum_prev_value(E value, std::ptrdiff_t n = 1) noexcept -> detail::enable_if_t<E, optional<std::decay_t<E>>> { |
| 110 | using D = std::decay_t<E>; |
| 111 | constexpr std::ptrdiff_t count = detail::count_v<D, S>; |
| 112 | |
| 113 | if (const auto i = enum_index<D, S>(value)) { |
| 114 | const std::ptrdiff_t index = (static_cast<std::ptrdiff_t>(*i) - n); |
| 115 | if (index >= 0 && index < count) { |
| 116 | return enum_value<D, S>(static_cast<std::size_t>(index)); |
| 117 | } |
| 118 | } |
| 119 | return {}; |
| 120 | } |
| 121 | |
| 122 | template <typename E, detail::enum_subtype S = detail::subtype_v<E>> |
| 123 | [[nodiscard]] constexpr auto enum_prev_value_circular(E value, std::ptrdiff_t n = 1) noexcept -> detail::enable_if_t<E, std::decay_t<E>> { |
no outgoing calls
no test coverage detected