Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy up variant type tests #191

Open
tomjnixon opened this issue Jan 12, 2024 · 0 comments · May be fixed by #195
Open

tidy up variant type tests #191

tomjnixon opened this issue Jan 12, 2024 · 0 comments · May be fixed by #195

Comments

@tomjnixon
Copy link
Member

tomjnixon commented Jan 12, 2024

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 tomjnixon linked a pull request Jan 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant