diff --git a/include/nameof.hpp b/include/nameof.hpp index 1ae15ee..f0f7bdb 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -571,14 +571,18 @@ constexpr auto values(std::index_sequence) noexcept { constexpr bool valid[sizeof...(I)] = {is_valid(I)>()...}; constexpr std::size_t count = values_count(valid); - E values[count] = {}; - for (std::size_t i = 0, v = 0; v < count; ++i) { - if (valid[i]) { - values[v++] = value(i); + if constexpr (count > 0) { + E values[count] = {}; + for (std::size_t i = 0, v = 0; v < count; ++i) { + if (valid[i]) { + values[v++] = value(i); + } } - } - return to_array(values, std::make_index_sequence{}); + return to_array(values, std::make_index_sequence{}); + } else { + return std::array{}; + } } template > @@ -609,10 +613,10 @@ template inline constexpr auto count_v = values_v.size(); template > -inline constexpr auto min_v = static_cast(values_v.front()); +inline constexpr auto min_v = (count_v > 0) ? static_cast(values_v.front()) : U{0}; template > -inline constexpr auto max_v = static_cast(values_v.back()); +inline constexpr auto max_v = (count_v > 0) ? static_cast(values_v.back()) : U{0}; template > constexpr std::size_t range_size() noexcept {