CppCon 2018: Arno Lepisk “Avoiding Disasters with Strongly Typed C++”

Опубликовано: 12 Октябрь 2018
на канале: CppCon
6,604
100

http://CppCon.org

Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/CppCon/CppCon2018

C++ is often described as a type-safe language — the compiler will not allow the programmer to mix types freely. But do we really use C++ in a type-safe manner? When a programmer uses the same type to represent different quantities, one could argue that the compiler's type-checks are bypassed and errors due to mix-ups not only become possible, but frequent! In this session a solution to this problem will be presented — strong types.

Strong types are a type-safe alternative to typedefs — but where typedefs only provide documentation and ease of writing, their strong counterparts are actually enforced by the compiler. We will explore how they work, and how using them can improve code quality. We will look at how one can implement a strong typedef by oneself, but also look at some of the readily available implementations which are available.

Finally we will look at how we can handle some special cases, e.g. where we need to allow two different strong types to interact with each other in well defined ways. These could be types representing two different linked quantities like positions and offsets; or scaled versions of the same quantity like different units of length.

Arno Lepisk, HiQ
Software engineer

Arno first came into contact with C++ in the late 90's. After getting a masters degree in engineering physics he has been programming professionally in C++ for over a decade, mostly for different embedded applications within industrial control, defense, gaming, and tele- and datacom.

Videos Filmed & Edited by Bash Films: http://www.BashFilms.com

*-----*
Register Now For CppCon 2022: https://cppcon.org/registration/
*-----*