diff --git a/include/utempl/utils.hpp b/include/utempl/utils.hpp index fc87b83..f45f5e8 100644 --- a/include/utempl/utils.hpp +++ b/include/utempl/utils.hpp @@ -317,9 +317,12 @@ concept UnpackConcept = [](std::index_sequence) { template concept TransformConcept = [](std::index_sequence) { - return ((std::invocable(std::declval()))> && - !std::same_as(std::declval()))>, void>) && - ...); + return ([] { + if constexpr(std::invocable(std::declval()))>) { + return !std::same_as(std::declval()))>, void>; + }; + return false; + }() && ...); }(std::make_index_sequence>()); template @@ -422,7 +425,12 @@ struct LeftFold { template concept LeftFoldConcept = decltype(Unpack(std::declval(), [](Ts&&...) { - return kWrapper<(std::convertible_to, T> && ...)>; + return kWrapper<([] { + if constexpr(std::invocable) { + return std::convertible_to, T>; + }; + return false; + }() && ...)>; }))::kValue; } // namespace impl @@ -518,7 +526,11 @@ namespace impl { template concept FilterConcept = decltype(Unpack(std::declval(), [](Ts&&...) { - return kWrapper<((std::invocable && std::convertible_to, bool>) && ...)>; + return kWrapper<([] { + if constexpr(std::invocable) { + return std::convertible_to, bool>; + }; + }() && ...)>; }))::kValue; } // namespace impl @@ -661,7 +673,14 @@ concept ComparableSwitchConcept = decltype(Unpack(std::declval(), []< template concept CallableSwitchConcept = std::same_as || decltype(Unpack(std::declval(), [](Ts&&...) { - return kWrapper<(std::convertible_to, std::optional> && ...)>; + return kWrapper<([] { + if constexpr(std::invocable) { + if constexpr(!std::same_as, void>) { + return std::convertible_to, std::optional>; + }; + }; + return false; + }() && ...)>; }))::kValue; } // namespace impl @@ -673,7 +692,7 @@ template F, std::invocable Default = decltype(kDefaultCreator)> constexpr auto Switch(KeysTuple&& keysTuple, ValuesTuple&& valuesTuple, Key&& key, F&& f, Default&& def = {}) -> R - requires std::move_constructible || std::same_as + requires(std::move_constructible || std::same_as) && (kTupleSize == kTupleSize) { return Unpack(std::forward(keysTuple), [&](Keys&&... keys) { return Unpack(std::forward(valuesTuple), [&](Values&&... values) { @@ -682,7 +701,13 @@ constexpr auto Switch(KeysTuple&& keysTuple, ValuesTuple&& valuesTuple, Key&& ke return std::forward(keys) == std::forward(key) ? (std::forward(f)(std::forward(values)), true) : false; }...}, - false); + false) + ? void(std::ignore) + : [&] { + if constexpr(!std::same_as)>) { + std::forward(def)(); + }; + }(); } else { return *FirstOf(Tuple{[&] { return std::forward(keys) == std::forward(key) ? std::forward(f)(std::forward(values))