On Sunday, 20 November 2016 at 16:36:18 UTC, Q. Schroll wrote:
How can I have relative-@attrib functions without unnecessary manual overloading?


import std.traits;

auto f1(DG) (DG dg) if (isCallable!DG && Parameters!DG.length == 1 && is(Parameters!DG[0] == int)) { // check other things here too, like return type
  return dg(1);
}

void main () pure {
  f1((int x) => 2*x); // ok, f1 is pure
//f1(x => 2*x); // alas, now you have to manually specify argument types
}


not the best solution, of course, and you can't do that without templates ('cause `nothrow` or `@nogc` *can* require different machine code in the future).

Reply via email to