digitalmars.D.learn - Convert delegate or function type to other.
- Rufus Smith (4/4) Jul 18 2016 Suppose I have the following: alias func = void function(int);
- Jacob Carlborg (4/7) Jul 18 2016 https://dlang.org/phobos/std_functional.html#toDelegate
- Rufus Smith (5/13) Jul 18 2016 No, that converts an actual function. I need to create a new
- Jacob Carlborg (12/16) Jul 18 2016 You can explicitly set the context pointer using the "ptr" property:
- John (3/7) Jul 18 2016 import std.traits;
- Rufus Smith (2/10) Jul 18 2016 Thanks, I guess that allows me to change the parameters too!
Suppose I have the following: alias func = void function(int); Is there a way to convert it automatically to something the same type except of delegate: alias del = toDel(func) = void delegate(int);?
Jul 18 2016
On 2016-07-18 20:49, Rufus Smith wrote:Suppose I have the following: alias func = void function(int); Is there a way to convert it automatically to something the same type except of delegate: alias del = toDel(func) = void delegate(int);?https://dlang.org/phobos/std_functional.html#toDelegate -- /Jacob Carlborg
Jul 18 2016
On Monday, 18 July 2016 at 18:51:29 UTC, Jacob Carlborg wrote:On 2016-07-18 20:49, Rufus Smith wrote:No, that converts an actual function. I need to create a new alias from the old one. I'd also like to be able to create a delegate with a different context pointer.Suppose I have the following: alias func = void function(int); Is there a way to convert it automatically to something the same type except of delegate: alias del = toDel(func) = void delegate(int);?https://dlang.org/phobos/std_functional.html#toDelegate
Jul 18 2016
On 2016-07-18 21:19, Rufus Smith wrote:No, that converts an actual function. I need to create a new alias from the old one.You mean the actual type? John's answer will give you that.I'd also like to be able to create a delegate with a different context pointer.You can explicitly set the context pointer using the "ptr" property: class Foo { void bar() {} } void delegate() dg; dg.ptr = cast(void*) new Foo; dg.funcptr = &Foo.bar; // not sure if this requires a cast -- /Jacob Carlborg
Jul 18 2016
On Monday, 18 July 2016 at 18:49:22 UTC, Rufus Smith wrote:Suppose I have the following: alias func = void function(int); Is there a way to convert it automatically to something the same type except of delegate: alias del = toDel(func) = void delegate(int);?import std.traits; alias del = ReturnType!func delegate(Parameters!func);
Jul 18 2016
On Monday, 18 July 2016 at 20:15:30 UTC, John wrote:On Monday, 18 July 2016 at 18:49:22 UTC, Rufus Smith wrote:Thanks, I guess that allows me to change the parameters too!Suppose I have the following: alias func = void function(int); Is there a way to convert it automatically to something the same type except of delegate: alias del = toDel(func) = void delegate(int);?import std.traits; alias del = ReturnType!func delegate(Parameters!func);
Jul 18 2016