Loading…
Attending this event?
CppNorth 2024, The Canadian C++ Conference
July 21-24, 2024 • Toronto, Canada
At the Microsoft Canadian Headquarters (Suite 4400)
In: CIBC SQUARE, 81 Bay St., Toronto, ON M5J 0E7, Canada
Wednesday July 24, 2024 13:00 - 14:00 EDT
This talk is about type erasure in C++ (I have to be specific because the term has a completely different meaning in other languages). The aim of this talk is to explain how type erasure works, and do it in a very simple and clear way.
Type erasure is probably the closest C++ comes to “and then magic happens.” It’s a technique used to write a program (in a strictly typed language, no less) that doesn’t mention the types it works with. It is the pinnacle of abstraction in C++, and, like most abstractions, it’s much easier to show what that looks like than to define it: most concise definitions of type erasure are circular. So we will begin the talk by demonstrating what the code looks like after the magic happens.
Then comes the biggest letdown of all time: I’ll show the basic technique that type erasure relies on. It’s very simple, it’s very familiar, it predates C++, and every implementation of type erasure uses it.
After that, we learn three basic ways to implement type erasure. There are several great type erasure libraries out there, you should use them if you just want to get stuff done. I’m going to strip them down to the bare minimum to show the essence of each implementation as clearly as possible. Along the way, we will learn how vtables are implemented.
Finally, we will measure and compare the performance of the different implementations of type erasure. Type erasure is easy to implement; fast type erasure is not really any harder to implement, but it relies on some subtle details I’m going to demonstrate (including how to make std::function 50% faster).
Whether you want to write your own implementation or use an existing library, by the end of this talk the type erasure will no longer be shrouded in a mystic aura for you.
Speakers
avatar for Fedor G Pikus

Fedor G Pikus

Fellow, Siemens EDA
Fedor G Pikus is a Technical Fellow and the Director of the Advanced Projects Team in Siemens Digital Industries Software. His responsibilities include planning the long-term technical direction of Calibre products, directing and training the engineers who work on these products... Read More →
Wednesday July 24, 2024 13:00 - 14:00 EDT
Track A

Attendees (3)


Sign up or log in to save this to your schedule, view media, leave feedback and see who's attending!

Share Modal

Share this link via

Or copy link