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…
unionboth run in about 7ms
exnruns in about 1010ms
So using exceptions as control flow in C++ is about 140x slower.