Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
import std.stdio; import std.string; import std.traits; import std.typetuple; mixin template Delay(alias Call, Args...) { ReturnType!Call Delay() { return Call(Args[0]); }; } @property string getMapperMixin(size_t count)() { string result; string[] mixinDecls; string[] tupleList; foreach (idx; 0 .. count) { mixinDecls ~= xformat("mixin .Delay!(Call, Args[%s]) Del%s;", idx, idx); tupleList ~= xformat("Del%s.Delay", idx); } string tupleStr = "alias TypeTuple!("; tupleStr ~= tupleList.join(","); tupleStr ~= ") Map;"; string mixinStr = mixinDecls.join("\n"); result = mixinStr ~ "\n" ~ tupleStr; return result; } template Map(alias Call, Args...) { /** Expands to (when length is 2): mixin .Delay!(Call, Args[0]) Del1; mixin .Delay!(Call, Args[1]) Del2; alias TypeTuple!( Del1.Delay, Del2.Delay ) Map; */ mixin(getMapperMixin!(Args.length)); } int functor(int arg) { return arg * 10; } void initCall(Args...)(Args args) { print( Map!(functor, args) ); } void print(T...)(T args) { foreach (arg; args) writef("%s ", arg); writeln(); } void main() { int x = 1; int y = 2; initCall(x, y); }
Result:
Success
/
Return code: 0
/
Compilation time:
1.258
seconds
/
Run time:
0.001
seconds
Disassembly
Application output:
10 20
Username
Message
Add comment
Paste info
Author:
Guest
Views:
157
Private:
no
Expires:
Never
Uploaded:
17.10.12 5:55
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.060
Pointer size:
m32
Actions
Download
Fork
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason