From ec87fc976c04302908def75c9e9fb52a762cbbbd Mon Sep 17 00:00:00 2001 From: "Pavel I. Kryukov" Date: Sat, 19 Feb 2022 13:26:06 +0300 Subject: [PATCH] Convert std::enable_if_t to static_assert for cleaner error message (#146) --- include/magic_enum.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index eb8f68e..5b916be 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -938,7 +938,8 @@ constexpr std::optional fuse_enum(E head, Es... tail) noexcept { // Returns a bijective mix of several enum values. This can be used to emulate 2D switch/case statements. template -[[nodiscard]] constexpr auto enum_fuse(Es... values) -> std::enable_if_t<(std::is_enum_v> && ...), std::optional> { +[[nodiscard]] constexpr auto enum_fuse(Es... values) { + static_assert((std::is_enum_v> && ...), "magic_enum::enum_fuse works only with enums"); static_assert(sizeof...(Es) >= 2, "magic_enum::enum_fuse requires at least 2 enums"); static_assert((detail::log2(enum_count() + 1) + ...) <= (sizeof(std::uintmax_t) * 8), "magic_enum::enum_fuse does not work for large enums"); const auto fuse = fusion_detail::fuse_enum(values...);