Created
September 28, 2010 06:50
-
-
Save sinfu/600535 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 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