Closed yuqian90 closed 5 years ago
My observation is that GCC for example does not optimize as well as Clang does for the recursive if
-else
chain. I had observed this via the chain of ternary operators approach in #56, but here's a concrete example with your code: https://godbolt.org/z/SsbjYZ
This is not an issue, it's a question. I want to ask, why does mpark::variant not adopt a simple implementation using recursive if else?
I hacked up something like this (no error checking, not carefully tested). It can be made to work with single-visitation. I think it's easy to extend to multi-visitation too. I did some benchmark on visit2() using the benchmark problem provided on the author's blog https://mpark.github.io/programming/2019/01/22/variant-visitation-v2/
I can't seem to tell any difference between mpark::visit() and visit2() in terms of performance (both compile time and runtime) when -O3 optimization is turned on. (i only tried with clang++6.0).
I'm asking because the switch case implementation in mpark::variant looks great but it is complicated. I wonder what's wrong with simple recursive if-else like this.