Skip to content

Instantly share code, notes, and snippets.

@jll63
Last active July 29, 2020 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jll63/d6575d2ec5318c355f164e529453db73 to your computer and use it in GitHub Desktop.
Save jll63/d6575d2ec5318c355f164e529453db73 to your computer and use it in GitHub Desktop.
template Params(alias fun) {
static if (is(typeof(fun) P == __parameters)) {
alias Params = P;
}
}
template forward(alias fun) {
static foreach(idx, overload; __traits(getOverloads, __traits(parent, fun), __traits(identifier, fun)))
@(__traits(getAttributes, overload)) auto forward(Params!overload p) {
return fun(p);
}
}
@("foo")
void myfun(int a, ref double b, out string c) {
b += 5.0;
c = "omg";
}
int myfun(in string a, inout double b) {
return 40;
}
import core.stdc.time;
void set (time_t value = time(null)) {
import std.stdio;
writeln(value);
}
void main() {
double b = 4.3;
string s = "asdas";
forward!myfun(4, b, s);
forward!set();
import std.stdio;
writeln(b, s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment