Skip to content

tidy up variant type tests #191

Description

@tomjnixon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions