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);
}

--

--

--

Computer graphics developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Google Phone Interview

How to Create and Use Dynamic and Static Libraries

My Job Hunting Story after a Coding Bootcamp

Docker for Python-Dash & R-Shiny

5th July

TPC 2.0 — HOW WE RE-STARTED

Citrix 1Y0-341 Exam Prep Tips: Schedule Your Certification

https://www.vmexam.com/citrix/citrix-1y0-341-ccp-n-certification-exam-syllabus

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
Timur Gafarov

Timur Gafarov

Computer graphics developer

More from Medium

How to Add Third Party Domain in Shopify? | EcomHeroes

How to fix NVM slowing down terminal startup on Mac

bodyParser.json() vs express.json() & express.urlencoded() vs express.json()

Magento2.4.1 Search Return No Result