Skip to content

Instantly share code, notes, and snippets.

@sinfu
Created September 28, 2010 06:50
Show Gist options
  • Save sinfu/600535 to your computer and use it in GitHub Desktop.
Save sinfu/600535 to your computer and use it in GitHub Desktop.
import std.meta;
void main()
{
Struct!(int, "x", double, "y") s;
s.x = 10;
s.y = 20.35;
}
struct Struct(TypesNames...)
{
alias staticStride!(2, TypesNames ) Types;
alias staticStride!(2, TypesNames[1 .. $]) names;
mixin mixinAll!(staticMap!(Declare,
staticZip!(Wrap!Types,
Wrap!names)));
}
template Declare(alias wrap_)
{
template Declare(alias wrap = wrap_)
{
// at!0 = type, at!1 = name
mixin("wrap.at!0 " ~ wrap.at!1 ~ ";");
}
}
// std.mixins?
template mixinAll(mixins...)
{
static if (mixins.length == 1)
{
alias mixins[0] it;
mixin it;
}
else static if (mixins.length >= 2)
{
mixin mixinAll!(mixins[ 0 .. $/2]);
mixin mixinAll!(mixins[$/2 .. $ ]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment