Skip to content

Commit c90c2ca

Browse files
committed
add ContainsProxied template
works like Contains, but in case there is a Proxy!T, it is also matched for T.
1 parent 5818b5a commit c90c2ca

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

source/mir/serde.d

+38
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,44 @@ template deserializeValueMemberImpl(alias deserializeValue, alias deserializeSco
23162316
}
23172317
}
23182318

2319+
// copied from std.meta
2320+
private template isSame(alias a, alias b)
2321+
{
2322+
static if (!is(typeof(&a && &b)) // at least one is an rvalue
2323+
&& __traits(compiles, { enum isSame = a == b; })) // c-t comparable
2324+
{
2325+
enum isSame = a == b;
2326+
}
2327+
else
2328+
{
2329+
enum isSame = __traits(isSame, a, b);
2330+
}
2331+
}
2332+
// copied from std.meta
2333+
private template isSame(A, B)
2334+
{
2335+
enum isSame = is(A == B);
2336+
}
2337+
2338+
/++
2339+
works like $(REF Contains, mir,internal,meta), but also checks if @serdeProxy
2340+
tagged types match.
2341+
+/
2342+
template ContainsProxied(Types...)
2343+
{
2344+
import mir.internal.meta : Contains;
2345+
2346+
enum ContainsProxied(T) =
2347+
(() {
2348+
// copied from std.meta : staticIndexOf
2349+
static foreach (Rhs; Types)
2350+
static if (isSame!(T, Rhs) || isSame!(T, serdeGetFinalProxy!Rhs))
2351+
// `if (__ctfe)` is redundant here but avoids the "Unreachable code" warning.
2352+
if (__ctfe) return true;
2353+
return false;
2354+
}());
2355+
}
2356+
23192357
private:
23202358

23212359
auto fastLazyToUpper()(return scope const(char)[] name)

0 commit comments

Comments
 (0)