Constraining templates before and after C++20 - The what, the how, and the why
Johannes Kalmbach
The simplest template declaration template <typename T> class C {...}; is often misleading. Most templates, both classes and functions, do not accept arbitrary types but impose additional constraints on their template arguments. When these constraints are absent from the template declaration, the compiler leaks implementation details through often-unreadable error messages when template instantiation fails because of invalid template arguments.
This talk provides a comprehensive overview of constraint techniques available in C++17 and earlier (particularly SFINAE-based approaches like std::enable_if and std::void_t) as well as concepts and requires clauses that have revolutionized template constraints since C++20.
We will also explore how to effectively use macros to bridge both approaches with a unified syntax, gaining the improved ergonomics of C++20 concepts while maintaining compatibility with older standards.
Johannes Kalmbach
I am a researcher and PhD candidate at the University of Freiburg where I use modern C++ to build QLever, a highly efficient RDF graph database for knowledge graphs with hundreds of billions of statements. I have recently cofounded QLeverize AG which provides commercial support for QLever