Re: Given an object, how to call an alias to a member function on it?

2023-05-03 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 3 May 2023 at 11:26:00 UTC, ag0aep6g wrote: On 03.05.23 13:13, Nick Treleaven wrote: void fun(alias method)(C c) {     void delegate() dg =     dg(); } No, it doesn't. You're not using the alias. You're just accessing `c.method` directly. If the actual method weren't

Re: Given an object, how to call an alias to a member function on it?

2023-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 2 May 2023 at 13:57:23 UTC, Steven Schveighoffer wrote: Isn't that what `__traits(child)` is for? https://dlang.org/spec/traits.html#child Yes, __traits(child, object, method_alias)(args) is the way to do it.

Re: Given an object, how to call an alias to a member function on it?

2023-05-03 Thread ag0aep6g via Digitalmars-d-learn
On 03.05.23 13:13, Nick Treleaven wrote: On Tuesday, 2 May 2023 at 13:06:41 UTC, ag0aep6g wrote: void fun(alias method)(C c) {     void delegate() dg;     dg.funcptr =     dg.ptr = cast(void*) c;     dg(); } This also works: void fun(alias method)(C c) {     void delegate() dg =    

Re: Given an object, how to call an alias to a member function on it?

2023-05-03 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 2 May 2023 at 13:06:41 UTC, ag0aep6g wrote: void fun(alias method)(C c) { void delegate() dg; dg.funcptr = dg.ptr = cast(void*) c; dg(); } This also works: void fun(alias method)(C c) { void delegate() dg = dg(); }

Re: cast expressions

2023-05-03 Thread Dennis via Digitalmars-d-learn
On Wednesday, 3 May 2023 at 09:03:38 UTC, Dom DiSc wrote: I know, (c) is a constructor call, but for basic types that's the same as (a) isn't it? No, a cast allows for overflow `cast(ubyte) 256`, while the constructor needs an integer that fits. `ubyte(256)` is an error. If t provides a