https://www.cppnow.org
---
Unit Testing an Expression Template Library in C++20 - Braden Ganetsky - C++Now 2024
---
Expression templates are one of the wonders that set C++ apart from all other programming languages. Using just the C++ type system, we can store arbitrary information in a type, giving us a way to calculate anything at compile-time. As years have gone by, we now have new ways of expressing compile-time computation, removing the need for relics of the past like expression templates. However, for some of us, expression templates remain a fascination, bordering on obsession.
Regardless of the paradigm, unit testing code at compile-time is no trivial matter. In very rare cases, a compiler's output can vary between compile-time and run-time, given identical source code. Therefore, in order to properly unit test a library meant for compile-time computation, we must run compile-time tests.
This talk will use an expression template parser combinator library as a case study to delve into the world of compile-time testing. Triggering a conditional miscompile is easy, but we all know that C++ compiler output can get notoriously unruly upon hitting errors. Therefore, we will explore ways to attain as much readability as possible in our diagnostics and error messages. Throughout the talk, we will contrast the popular unit testing libraries' solutions to compile-time testing, and we will learn which features are left to be desired. We will push the language to its limits to achieve the most user-friendly error messages we can get, while looking back on how far C++ has come in terms of compile-time programming. Ultimately, we will end up where all C++ users eventually stand: wanting more features out of the language. We will end with a roadmap of sorts, showing which future versions of C++ are slated to render our compile-time testing much simpler and more expressive than we can achieve today, and which desired features have yet to commence the standardization pipeline.
---
Slides: https://github.com/boostcon/cppnow_presentations_2024/blob/main/Presentations/Unit_Testing_an_Expression_Template_Library_in_Cpp20.pdf
---
Braden Ganetsky
Braden Ganetsky graduated from the University of Manitoba with a degree in mechanical engineering, fueled by his passion for mechanical puzzles. During his final year of school, when all classes and activities were remote, he discovered C++ and has been hooked ever since. He interned as a C++ developer, which turned into a full time job, completing a successful pivot of his career. Now, he spends his days working on supply chain software, and spends his nights working on fun projects like parser combinators, and getting involved in the C++ community.
---
C++Now 2025 - 28th April - 2nd May
C++Now is an annual onsite international C++ programming and coding conference held in Aspen, Colarado. For all C++ developers, C++ software engineers and those involved with the C++ language, CppNow provides an indepth and technical content provided by the best and brightest C++ experts of the C++ world.
Annual CppNow Conference - https://www.cppnow.org
https://www.linkedin.com/company/cppnow
https://twitter.com/cppnow
https://www.facebook.com/CppNow
https://www.reddit.com/r/CppNow
https://mastodon.social/@cppnow
Video Sponsors: millennium and think-cell
---
Videos Filmed & Edited By Bash Films: https://bashfilms.com/
YouTube Channel Managed & Optimized By Digital Medium Ltd: https://events.digital-medium.co.uk
---
#boost #cpp #cppprogramming #cplusplus #softwareengineering