Niall Douglas wrote:
What does it mean tha "outcome is equally costly on T or E branches chosen"?
Have a look at https://godbolt.org/g/bVd4D7, specifically the disassembly.
As a side note, the Clang/LLVM optimizer is indeed impressive. printf("a") -> putchar('a'), which is just one example of what it can do.
As you'll note, the first possible state (empty) tends to be chosen by the compiler as the most likely. That implies a 20 cycle branch misprediction cost for each of the valued or errored states. So they are equally costly, which is intentional.
Wait a minute. Are you saying that you consider the fact that valued and errored are equally slow a feature, instead of one of them being fast? How is that a good thing? Of course empty should be the least likely - it _is_ the least likely.