Loading…
C++Now 2021 has ended
Thursday, May 6 • 9:00am - 10:30am
Variations on variants

Log in to save this to your schedule, view media, leave feedback and see who's attending!

std::variant was added to C++ in 2017 as a type-safe alternative to C's union.
To start us off, I will shortly introduce the rationale of std::variant and the typical ways in which it can be used. I will also try to give insights into the way std::variant is typically implemented, highlighting the memory layout and its run-time performance implications.
The bulk of the talk will then focus on the key differences between std::variant and union, and discuss a common use-case where unions are typically used which std::variant does not support - serialization of streams of a trivially copyable object to files or to network. Then, I'll suggest approaches to tackle this shortcoming: Intrusive-Variant, Variant-of-Base. When presenting and describing the approaches above, I will dive deeper into what the C++ standard says about unions and their pitfalls, and discuss reasoning and issues. Time permitting, I'll finish off with a counterintuitive uses of std::variant - simple and safe mechanism for de-virtualization.
After attending this talk, participants should be better equipped to use this relatively new concept to modernize existing low-level C style code and will have a better understanding of how variants work under the hood.

Speakers
avatar for Roi Barkan

Roi Barkan

Istra Research
Professional software developer and architect since 2000, Roi's main focus throughout his career was on high performance and distributed systems, implementing complex and innovative algorithms. Roi is the SVP technologies of Istra Research, where he helps creating low latency financial... Read More →


Thursday May 6, 2021 9:00am - 10:30am MDT
C