libadm icon indicating copy to clipboard operation
libadm copied to clipboard

tidy up variant type tests

Open tomjnixon opened this issue 2 years ago • 0 comments

To check which type a variant holds, both v.which() == x and v.type() == typeid(T) are used,, and i'm not keen on either. The options are:

  • v.which(): Fast, small code, but it would be better to not have to find the type index.
  • v.type(): Slow (often ends up as a string compare), lots of code, and implies use of RTTI.
  • boost::get<T>(&v) != nullptr: Arguably the proper way to do it, but generates more code than v.which() on gcc, and MSVC fails to optimise it and generates a whole bunch of nonsense
  • use a visitor: similar code to get (as boost implements get with a visitor)

I think we should replace these with v.which() and some template magic to find the right index:

https://gcc.godbolt.org/z/ed3zv1b9M

If you turn the "library functions" filter off on MSVC you can see all the extra stuff generated for some options; this goes away if you remove the non-which options.

tomjnixon avatar Jan 12 '24 13:01 tomjnixon