| 739 | |
| 740 | template<typename T> |
| 741 | inline auto next_enum_item(T v, bool wrap = true) -> typename df::enum_traits<T>::enum_type |
| 742 | { |
| 743 | using traits = df::enum_traits<T>; |
| 744 | |
| 745 | if constexpr (complex_enum<T>) |
| 746 | { |
| 747 | const auto& complex = traits::complex; |
| 748 | const auto it = complex.value_index_map.find(v); |
| 749 | if (it != complex.value_index_map.end()) |
| 750 | { |
| 751 | if (!wrap && it->second + 1 == complex.size()) |
| 752 | { |
| 753 | return T(traits::last_item_value + 1); |
| 754 | } |
| 755 | size_t next_index = (it->second + 1) % complex.size(); |
| 756 | return T(complex.index_value_map[next_index]); |
| 757 | } |
| 758 | else |
| 759 | return T(traits::last_item_value + 1); |
| 760 | } |
| 761 | else |
| 762 | { |
| 763 | using base_type = typename traits::base_type; |
| 764 | base_type iv = base_type(v); |
| 765 | if (iv < traits::last_item_value) |
| 766 | { |
| 767 | return T(iv + 1); |
| 768 | } |
| 769 | else |
| 770 | { |
| 771 | if (wrap) |
| 772 | return traits::first_item; |
| 773 | else |
| 774 | return T(traits::last_item_value + 1); |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * Check if the value is valid for its enum type. |
no test coverage detected