How to dispatch a class function for an object accessed by handle?
wjoe
invalid at example.com
Fri Mar 6 15:05:56 UTC 2020
On Friday, 6 March 2020 at 14:14:04 UTC, Adam D. Ruppe wrote:
> On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer
> wrote:
>> Adam's way doesn't work either, because the call doesn't use
>> the alias, but just instantiates opDispatch with the new name!'
>
> oh yikes, how did I not notice that?!
>
> so yeah just kinda screwed. I'd probably suggest at tis point
> having the opDispatch be a trivial implementation that just
> forwards to another named method.
>
> struct A {
> template opDispatch(string name) {
> auto opDispatch(T, Args...)(Args args) {
> return other_name!(name, T, Args)(args);
> }
> }
>
> auto other_name(string name, T, Args...)(Args args) {
> // real implementation
> }
> }
>
>
> and then to test it externally you do
>
> a.other_name!("whatever", Bitmap)(args, here);
This isn't the worst thing to use and since it's just for testing
it's fine.
I came up with a similar interface like a.other_name!("whatever",
Bitmap)(args, here); after discarding .opDispatch() and I called
the thing
.dispatch(T, string fn, ARGS...)(...).
But didn't like the string part and that's when I introduced the
alias fn because I figured maybe it's possible to do something
like:
factory.dispatch!(Bitmap.load)(handle, path);
and get the Bitmap part from that alias and hence save the
duplicate Bitmap type in factory.dispatch!(Bitmap,
Bitmap.load)(...);
Anyways thanks for your help.
More information about the Digitalmars-d-learn
mailing list