3 Jun
2017
3 Jun
'17
9:49 a.m.
Vicente J. Botet Escriba wrote:
If we had to define a monadic interface for std::variant
, I'm sure that the std::variant implementer would have a hidden narrow access to its elements and will not use neither get_if nor visit. Well, this is what I will do to avoid to have to ensure/check that there is no cost while using get_if/visit.
On gcc/clang there is no cost for using *get_if<> instead of a private accessor, and depending on how get<> is written, there can be no cost to using it as well. I did switch from get<> to private accessors within the variant implementation, but that's mostly because I want to generate aesthetically pleasing assembly on Compiler Explorer and not because there is a measurable cost to using get<>.