From c90c2ca5129434b9d845a76dda3dc735fe8210f8 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Fri, 24 Jun 2022 23:33:00 +0200 Subject: [PATCH] add ContainsProxied template works like Contains, but in case there is a Proxy!T, it is also matched for T. --- source/mir/serde.d | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/mir/serde.d b/source/mir/serde.d index f7cd58c1..5a8791d5 100644 --- a/source/mir/serde.d +++ b/source/mir/serde.d @@ -2316,6 +2316,44 @@ template deserializeValueMemberImpl(alias deserializeValue, alias deserializeSco } } +// copied from std.meta +private template isSame(alias a, alias b) +{ + static if (!is(typeof(&a && &b)) // at least one is an rvalue + && __traits(compiles, { enum isSame = a == b; })) // c-t comparable + { + enum isSame = a == b; + } + else + { + enum isSame = __traits(isSame, a, b); + } +} +// copied from std.meta +private template isSame(A, B) +{ + enum isSame = is(A == B); +} + +/++ +works like $(REF Contains, mir,internal,meta), but also checks if @serdeProxy +tagged types match. ++/ +template ContainsProxied(Types...) +{ + import mir.internal.meta : Contains; + + enum ContainsProxied(T) = + (() { + // copied from std.meta : staticIndexOf + static foreach (Rhs; Types) + static if (isSame!(T, Rhs) || isSame!(T, serdeGetFinalProxy!Rhs)) + // `if (__ctfe)` is redundant here but avoids the "Unreachable code" warning. + if (__ctfe) return true; + return false; + }()); +} + private: auto fastLazyToUpper()(return scope const(char)[] name)