Skip to content

Commit

Permalink
add ContainsProxied template
Browse files Browse the repository at this point in the history
works like Contains, but in case there is a Proxy!T, it is also matched for T.
  • Loading branch information
WebFreak001 committed Jun 24, 2022
1 parent 69868ac commit 3ff004e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions source/mir/serde.d
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,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)
Expand Down

0 comments on commit 3ff004e

Please sign in to comment.