Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct io { import std.stdio; }
- struct Bind(Args...)
- {
- Args args;
- this(Args args)
- {
- assert(args.length > 0);
- this.args = args;
- }
- auto opCall()
- {
- auto func = args[0];
- static if(args.length > 1)
- return func(args[1..$]);
- else
- return func();
- }
- }
- auto bind(FunctionType, Args...)(FunctionType func, Args args)
- {
- return Bind!(FunctionType, Args)(func, args);
- }
- auto bind(FunctionType)(FunctionType func)
- {
- return Bind!(FunctionType)(func);
- }
- void callme()
- {
- io.writeln("called");
- }
- void callmetoo(string stuff)
- {
- io.writeln("called with ", stuff);
- }
- void main()
- {
- bind(&callme)();
- bind(&callmetoo, "things")();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement