#pragma once #include "../common.hpp" #include #include #include #include namespace enchantum::details { template inline constexpr std::size_t prefix_length_or_zero = 0; template inline constexpr auto prefix_length_or_zero::prefix_length)> = std::size_t{ enum_traits::prefix_length}; template constexpr auto generate_arrays() { #if defined __clang__ && __clang_major__ >= 20 if constexpr (BitFlagEnum) { if constexpr (EnumFixedUnderlying) { constexpr std::size_t bits = sizeof(Enum) * CHAR_BIT; std::array ret{}; // 0 value reflected for (std::size_t i = 0; i < bits; ++i) ret[i + 1] = static_cast(static_cast>>(1) << i); return ret; } else { constexpr auto bits = []() { auto copy = (Max > Min ? Max - Min : Min - Max); // handle negative; std::size_t count = 0; do ++count; while (copy >>= 1); return count; }(); std::array b{}; // 0 value reflected for (std::size_t i = 0; i < bits; ++i) b[i + 1] = static_cast(static_cast>>(1) << i); return b; } } #else if constexpr (BitFlagEnum) { constexpr std::size_t bits = sizeof(Enum) * CHAR_BIT; std::array ret{}; // 0 value reflected for (std::size_t i = 0; i < bits; ++i) ret[i + 1] = static_cast(static_cast>>(1) << i); return ret; } #endif else { static_assert(Min < Max, "enum_traits::min must be less than enum_traits::max"); std::array array; auto* const array_data = array.data(); for (std::size_t i = 0, size = array.size(); i < size; ++i) array_data[i] = static_cast(static_cast(i) + Min); return array; } } } // namespace enchantum::details