From 359bed1b7d5182f241749353952d48d277909b2c Mon Sep 17 00:00:00 2001 From: sha512sum Date: Mon, 15 Jul 2024 18:33:37 +0000 Subject: [PATCH] Add additional checks to Default in Switch function --- include/utempl/utils.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/utempl/utils.hpp b/include/utempl/utils.hpp index f45f5e8..3054790 100644 --- a/include/utempl/utils.hpp +++ b/include/utempl/utils.hpp @@ -683,6 +683,17 @@ concept CallableSwitchConcept = std::same_as || decltype(Unpack(std::de }() && ...)>; }))::kValue; +template +concept DefaultSwitchConcept = [] { + if constexpr(std::invocable) { + if constexpr(!std::same_as) { + return std::convertible_to, std::optional>; + }; + return true; + }; + return false; +}(); + } // namespace impl template Key, impl::CallableSwitchConcept F, - std::invocable Default = decltype(kDefaultCreator)> + impl::DefaultSwitchConcept Default = decltype(kDefaultCreator)> constexpr auto Switch(KeysTuple&& keysTuple, ValuesTuple&& valuesTuple, Key&& key, F&& f, Default&& def = {}) -> R requires(std::move_constructible || std::same_as) && (kTupleSize == kTupleSize) {