Metaprogramming with Alias Sequences

import std.stdio;
import std.meta;
void main()
{
alias params = AliasSeq!("foo", "bar");
writeln(params);
}
writeln("foo", "bar");
alias params = AliasSeq!(0, 5, 10, 40);
assert(params[0..2] == AliasSeq!(0, 5));
static foreach(param; params)
{
writeln(param);
}
writeln("foo");
writeln("bar");
alias literals = AliasSeq!(5, "hello");
auto vars = literals;
vars[0] = 100;
writeln(vars);
struct Compound(T...)
{
T tuple;
alias tuple this;
}
Compound!(T) compound(T...)(T args)
{
return Compound!(T)(args);
}
auto someFunc()
{
return compound(true, 0.5f, "hello");
}
alias tuple = AliasSeq!(bool, float, string);
tuple t = someFunc();
void printClasses(alias modul)()
{
alias memberNames = AliasSeq!(__traits(allMembers, modul));
alias Member(string name) = Alias!(__traits(getMember, modul, name));
alias members = staticMap!(Member, memberNames);
enum bool isClass(alias T) = is(T == class);
alias memberClasses = Filter!(isClass, members);

static foreach(Type; memberClasses)
{
writeln(Type.stringof);
}
}
import mymodule;void main()
{
printClasses!(mymodule);
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store