digitalmars.D - Copying parameter lists verbatim
- Manu via Digitalmars-d (17/17) Jul 18 2014 So, about 2 years back I motivated a bunch of work on traits relating to
- Dicebot (4/4) Jul 19 2014 http://dlang.org/phobos/std_traits.html#ParameterIdentifierTuple
- Dicebot (4/4) Jul 19 2014 Also, vibe.d internal `cloneFunction` which generates copy of
- Jakob Ovrum (8/9) Jul 19 2014 Unfortunately the only way to create perfect forwarding functions
- Andrei Alexandrescu (2/10) Jul 19 2014 How can this be encapsulated as a library artifact? -- Andrei
- Jakob Ovrum (8/23) Jul 20 2014 Since the key parts of the forwarding function - the parameter
So, about 2 years back I motivated a bunch of work on traits relating to parameter lists. I'm looking at std.traits now, but I can't see one of the things that I could have sworn was added at the time. I need to clone a functions parameter list, including the names and default args. Ie. void f(int x, float y = 10); void myFunc(CloneParameterList!f) assert(myFunc.stringof == "void myFunc(int x, float y = 10)"); It wasn't that, but I recall agreeing that it was possible now... but I can't see how to do it. I thought it was implemented using a __traits, but nothing stands out to me. Looking at the source in std.traits, it refers to FunctionTypeOf, which I don't recall anything about when we were implementing this stuff initially. Perhaps there's been further development and changes since I last looked at it...? Anyway, does anybody know a nice tidy way to do it?
Jul 18 2014
http://dlang.org/phobos/std_traits.html#ParameterIdentifierTuple http://dlang.org/phobos/std_traits.html#ParameterDefaultValueTuple http://dlang.org/phobos/std_traits.html#ParameterTypeTuple ?
Jul 19 2014
Also, vibe.d internal `cloneFunction` which generates copy of method/function signature with fully qualified type names (for mixin hygiene): https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/internal/meta/codegen.d#L177
Jul 19 2014
On Saturday, 19 July 2014 at 06:13:10 UTC, Manu via Digitalmars-d wrote:Anyway, does anybody know a nice tidy way to do it?Unfortunately the only way to create perfect forwarding functions completely generically is still using an ugly string mixin that generates the forwarding function. A subset of forwarding functions can be created using templates and auto-ref, but of course a function template has many disadvantages to a concrete function (virtual functions being a good example).
Jul 19 2014
On 7/19/14, 9:36 AM, Jakob Ovrum wrote:On Saturday, 19 July 2014 at 06:13:10 UTC, Manu via Digitalmars-d wrote:How can this be encapsulated as a library artifact? -- AndreiAnyway, does anybody know a nice tidy way to do it?Unfortunately the only way to create perfect forwarding functions completely generically is still using an ugly string mixin that generates the forwarding function. A subset of forwarding functions can be created using templates and auto-ref, but of course a function template has many disadvantages to a concrete function (virtual functions being a good example).
Jul 19 2014
On Saturday, 19 July 2014 at 17:40:01 UTC, Andrei Alexandrescu wrote:On 7/19/14, 9:36 AM, Jakob Ovrum wrote:Since the key parts of the forwarding function - the parameter list and attribute list - are part of the signature, the entire function declaration has to be mixed in. That means the function body has to be provided as a string argument. This tends to cause some seriously unreadable code. It may be a lost cause but I'm hoping we can amend the language to avoid that.On Saturday, 19 July 2014 at 06:13:10 UTC, Manu via Digitalmars-d wrote:How can this be encapsulated as a library artifact? -- AndreiAnyway, does anybody know a nice tidy way to do it?Unfortunately the only way to create perfect forwarding functions completely generically is still using an ugly string mixin that generates the forwarding function. A subset of forwarding functions can be created using templates and auto-ref, but of course a function template has many disadvantages to a concrete function (virtual functions being a good example).
Jul 20 2014