| 1139 | typename Lambda, |
| 1140 | typename ResultGetterType> |
| 1141 | constexpr decltype(auto) constexpr_switch( |
| 1142 | Lambda&& lambda, |
| 1143 | typename std::decay_t<decltype(*GlobValues)>::value_type searched, |
| 1144 | ResultGetterType&& def, |
| 1145 | BinaryPredicate&& pred = {}) { |
| 1146 | using result_t = std::invoke_result_t<ResultGetterType>; |
| 1147 | using hash_t = std::conditional_t<has_duplicate<GlobValues, Hash>(), Hash, typename Hash::secondary_hash>; |
| 1148 | static_assert(has_duplicate<GlobValues, hash_t>(), "magic_enum::detail::constexpr_switch duplicated hash found, please report it: https://github.com/Neargye/magic_enum/issues."); |
| 1149 | constexpr std::array values = *GlobValues; |
| 1150 | constexpr std::size_t size = values.size(); |
| 1151 | constexpr std::array cases = calculate_cases<GlobValues, hash_t>(Page); |
| 1152 | |
| 1153 | switch (hash_v<hash_t>(searched)) { |
| 1154 | MAGIC_ENUM_FOR_EACH_256(MAGIC_ENUM_CASE) |
| 1155 | default: |
| 1156 | if constexpr (size > 256 + Page) { |
| 1157 | return constexpr_switch<GlobValues, CallValue, Page + 256, Hash>(std::forward<Lambda>(lambda), searched, std::forward<ResultGetterType>(def)); |
| 1158 | } |
| 1159 | break; |
| 1160 | } |
| 1161 | return def(); |
| 1162 | } |
| 1163 | |
| 1164 | #undef MAGIC_ENUM_CASE |
| 1165 | |