boostorg / boostorg/hof

[idea] adaptor for multiple virtual dispatch

Open
#162 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
509
Forks
94
PR merge metrics
No merged PRs in 30d

Description

I know you've got a lot on your plate right now, but I just wanted to run this idea by you. I think Fit is the perfect library candidate to offer a generic, maintainable solution to the multiple dispatch problem.

[This article](http://eli.thegreenplace.net/2016/a-polyglots-guide-to-multiple-dispatch/) on the topic was recently posted on Hacker News, and is an excellent overview of the problem (I was previously unfamiliar).

I haven't written any code yet, but I think it an adaptor template could be made.

The template would accept the following types:
- `F` - a user-defined function object class with `operator()` overloads to handle dispatch cases
- `B` - a base type pointer/reference
- `D...` - a variadic parameter list of derived type candidates (pointers/references)

The adaptor constructor would accept an `F` object, and keep it around as a data member (or something logically equivalent to that - you might have a better way of doing this with your magical macros).

The adaptor would supply an `operator()` expecting a number of `B` arguments, which then would be `dynamic_cast`-ed to each type in the `D...` list. The `F` instance would be invoked once all arguments had been `dynamic_cast`-ed successfully, passing the successfully casted pointers as arguments.

Does that make sense?

If you think this is something that belongs in Fit, I could try to come up with an implementation at a later point in time.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.