> But that is not the relevant pattern. What we require is the *joint*
> instantiation of A B and C types, and a dispatch that is specialized for
> this joint combination, and hence is as fast as possible.
The joint combination is straightforward:
template<class A, class B, class C>
void fooImpl(A a, B b, C c);
void foo(std::variant<A1..> avar,
std::variant<B1..> bvar,
std::variant<C1..> cvar)
{
std::visit(
[](auto a, auto b, auto c)
{
fooImpl(a, b, c);
},
avar, bvar, cvar);
}
but in this case, as you pointed out, we don't get much compile time
advantage - but we do still enjoy the fast dispatch.
> What you are describing (independent dispatching for every type) is not
> very different from dynamic typing, unless the code can be divided into
> clear disjoint blocks as in your example, which is not the case for most
> algorithms in graph-tool
I will defer to your judgment on that one, though perhaps surprisingly I
found this worked in the first (only) algorithm I tried applying it to: assortativity.
I selected it based on how long it took to build. The results were:
boost::any + typelist : 177s, 4.5GB memory
std::variant for edge weights only: 37s + 1.74GB
The memory reduction is very useful in that it enables parallel builds.
Best,
Jeff