logoalt Hacker News

tcfhgj • today at 5:54 PM • 2 replies • view on HN

are you sure?

https://stackoverflow.com/questions/69444641/c17-stdvariant-...


Replies

jasode • today at 6:41 PM

To add to sibling comment...

GCC 11 (2021) std::visit was slower than virtual dispatch.

GCC 12 (2022) optimized std::visit so it can be faster than virtual dispatch.

https://shubhankar-gambhir.github.io/posts/your-stdlib-imple...

creata • today at 6:18 PM

If you take the linked benchmark and use the latest compiler version, the std::variant version is faster. The annoying thing about std::variant (and with some other features of modern C++) is that it generates a bunch of code that the compiler has to optimize away.

➕ show 1 reply