From 6359caf2fa7c471180b87a7f56558cd6f7937e62 Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Tue, 6 Aug 2024 14:38:14 +0400 Subject: [PATCH 1/3] added contains_decayed to black_magic a variant of contains that compares types using std::decay --- include/crow/utility.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/crow/utility.h b/include/crow/utility.h index 7be9a814c..965f08c24 100644 --- a/include/crow/utility.h +++ b/include/crow/utility.h @@ -453,6 +453,19 @@ namespace crow struct contains : std::false_type {}; + template + struct contains_decayed : std::true_type + {}; + + template + struct contains_decayed : + std::conditional::type, typename std::decay::type>::value, std::true_type, contains_decayed>::type + {}; + + template + struct contains_decayed : std::false_type + {}; + template struct empty_context {}; From 9bf2f1e819d728ce6af9ebfb7950491301e15760 Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Tue, 6 Aug 2024 14:39:06 +0400 Subject: [PATCH 2/3] added is_superset_of to black_magic it checks if a type pack is a subset of another type pack using contains_decayed --- include/crow/utility.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/crow/utility.h b/include/crow/utility.h index 965f08c24..283911849 100644 --- a/include/crow/utility.h +++ b/include/crow/utility.h @@ -466,6 +466,19 @@ namespace crow struct contains_decayed : std::false_type {}; + template + struct type_pack + { + template + struct is_superset_of : std::true_type + {}; + + template + struct is_superset_of : + std::conditional::value, is_superset_of, std::false_type>::type + {}; + }; + template struct empty_context {}; From b46f6d5cde0126bd3387340dd91d04eb6e0fc2dc Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Tue, 6 Aug 2024 14:40:41 +0400 Subject: [PATCH 3/3] statically assert that template types passed to Crow are a subset of the types of the arguments passed to the constructor --- include/crow/app.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/crow/app.h b/include/crow/app.h index 6fd288222..c906215aa 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -708,6 +708,8 @@ namespace crow template std::tuple make_middleware_tuple(Ts&&... ts) { + static_assert(black_magic::type_pack::template is_superset_of::value, "Constructor argument types must be a subset of the Crow template types"); + auto fwd = std::forward_as_tuple((ts)...); return std::make_tuple( std::forward(