On 3/7/18 9:20 AM, Shachar Shemesh wrote:
import std.traits;
import std.stdio;

void func(int a, int b=2, int c=3) {
     return a+b+c;

void func2(Parameters!func args = ParameterDefaults!func) {
     return func(args);

void main() {

So, this does not compile. I can do that with a mixin, but I would much rather not. Is there a non-Mixin method of copying not only the function's signature, but also its default values?

Well, you could do it with templates, but obviously that is less desirable:

void func2(Args...)(Args args) if(is(typeof(func(args)))) { return func(args); }

The second thing I thought would be simple is to refer to call a struct's member.

struct S {
     void func(int a) {

unittest {
     alias v = S.func;

This is actually a function that requires a `this` pointer. It can't be called unless you stuff it in a delegate:

     S s;
     s.v(12); // No property v for type S

void delegate(int) dg;
dg.ptr = &s;
dg.funcptr = &v; // note you need the address operator

     // UFCS to the rescue!
     v(s, 12);


It would be nice if v(s, 12) worked. Related DIP: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1011.md


Reply via email to