Skip to content

Instantly share code, notes, and snippets.

@UplinkCoder
Last active August 12, 2021 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UplinkCoder/c2838252c55c9fdf4fc526e2a8c5ce7e to your computer and use it in GitHub Desktop.
Save UplinkCoder/c2838252c55c9fdf4fc526e2a8c5ce7e to your computer and use it in GitHub Desktop.
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