It's possible to return multiple types from a function in C++ by using exceptions! Unfortunately, it turns out that C++ exceptions are very slow. How slow? Well…
variant
andunion
both run in about 7msexn
runs in about 1010ms
So using exceptions as control flow in C++ is about 140x slower.
Ah, nice! I get similar performance just by deleting the copy constructor from my implementation.