hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.4K
active users

Šimon Tóth

The typeid operator can be applied to types and expressions and will return a reference to a std::type_info object representing the type (of the expression).

When applied to polymorphic types (except during construction and destruction), the typeid operator will evaluate the expression and return the dynamic type of the expression.

Compiler Explorer link: compiler-explorer.com/z/YxePzh

@simontoth Worth noting that one big downside of typeid() is that it is a template function which accepts a paramter by value. So if you give it a "const int&" it will copy it into an "int". This is kinda crappy output. using boost::typeindex::type_id_with_cvr; helps with that.

@braincell boost::typeindex post is scheduled for tomorrow.

But typeid is not a function, it's an operator, I don't think it should make copies, but I will doublecheck.

@simontoth I know this about the GCC implementation from 5 years ago, and I think MSVC did the same. It's implementation specific, so subject to change I guess.