Last active
August 12, 2021 08:07
-
-
Save UplinkCoder/c2838252c55c9fdf4fc526e2a8c5ce7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctx_ = ctx; | |
import std.meta; | |
template isStruct(alias S) | |
{ | |
static if (is(S == struct)) | |
{ | |
enum isStruct = true; | |
} | |
else | |
{ | |
enum isStruct = false; | |
} | |
} | |
template isFunction(alias F) | |
{ | |
static if (is(typeof(F) == function)) | |
{ | |
enum isFunction = true; | |
} | |
else | |
{ | |
enum isFunction = false; | |
} | |
} | |
template MemberOf(alias M) | |
{ | |
template MemberOfInner(string memberName) | |
{ | |
static if (is(mixin("M." ~ memberName)) || is(typeof(mixin("M." ~ memberName)))) | |
{ | |
alias MemberOfInner = mixin("M." ~ memberName); | |
} | |
} | |
alias MemberOf = MemberOfInner; | |
} | |
template MembersOf(alias M) | |
{ | |
template MembersOfInner(memberStrings...) | |
{ | |
alias MembersOfInner = staticMap!(MemberOf!M, memberStrings); | |
} | |
alias MembersOf = MembersOfInner; | |
} | |
template StructCollector(alias M) | |
{ | |
alias StructCollector | |
= Filter!(isStruct, staticMap!(MembersOf!M, __traits(allMembers, M))); | |
} | |
template FunctionCollector(alias M) | |
{ | |
alias FunctionCollector | |
= Filter!(isFunction, staticMap!(MembersOf!M, __traits(allMembers, M))); | |
} | |
template Params(alias F) | |
{ | |
static if (is(F == function)) | |
{ | |
static if (is(F P == __parameters)) | |
{ | |
alias Params = P; | |
} | |
} | |
else static if (is(typeof(F) P == __parameters)) | |
{ | |
alias Params = P; | |
} | |
else | |
{ | |
static assert(0, F.stringof ~ " is not a function"); | |
} | |
} | |
template FunctionHasParamType(alias F, alias P) | |
{ | |
alias FunctionHasParam = Filter!(isSame!P, Params!F); | |
} | |
alias Funcs = FunctionCollector!ctx_; | |
alias Structs = StructCollector!ctx_; | |
pragma(msg, Funcs); | |
pragma(msg, Structs); | |
template isSame(alias A) | |
{ | |
template isSameInner(alias B) | |
{ | |
enum isSameInner = !is(A == B); | |
} | |
alias isSame = isSameInner; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment