Skip to content

Commit 3ff004e

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 69868ac commit 3ff004e

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
@@ -2308,6 +2308,44 @@ template deserializeValueMemberImpl(alias deserializeValue, alias deserializeSco
23082308
}
23092309
}
23102310

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

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

0 commit comments

Comments
 (0)