Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ContainsProxied template #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions source/mir/serde.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down