How to dispatch a class function for an object accessed by handle?
Steven Schveighoffer
schveiguy at gmail.com
Fri Mar 6 14:42:48 UTC 2020
On 3/6/20 9:14 AM, 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);
> }
> }
Do this instead, I think this will work and avoids an extra call (and
having to do the argument plumbing that inevitably comes with this kind
of wrapping):
template opDispatch(string name) {
alias opdispatch(T) = other_name!(name, T);
}
template other_name(string name, T) {
auto other_name(Args...)(Args args) {
// real implementation
}
}
-Steve
More information about the Digitalmars-d-learn
mailing list