arsd.mvd

mvd stands for Multiple Virtual Dispatch. It lets you write functions that take any number of arguments of objects and match based on the dynamic type of each of them.

1 void foo(Object a, Object b) {} // 1
2 void foo(MyClass b, Object b) {} // 2
3 void foo(DerivedClass a, MyClass b) {} // 3
4 
5 Object a = new MyClass();
6 Object b = new Object();
7 
8 mvd!foo(a, b); // will call overload #2

The return values must be compatible; mvd will return the least specialized static type of the return values (most likely the shared base class type of all return types, or void if there isn't one).

All non-class/interface types should be compatible among overloads. Otherwise you are liable to get compile errors. (Or it might work, that's up to the compiler's discretion.)

Members

Aliases

CommonReturnOfOverloads
alias CommonReturnOfOverloads(alias fn) = CommonType!(staticMap!(ReturnType, __traits(getOverloads, __traits(parent, fn), __traits(identifier, fn))))

This exists just to make the documentation of mvd nicer looking.

Functions

mvd
CommonReturnOfOverloads!fn mvd(T args)

See details on the arsd.mvd page.

Meta

Suggestion Box / Bug Report