Six ways for implementing max: a walk through API design, dangling references and C++20 constraints

Amir Kirsh

online
60 minute session
beginner
intermediate
advanced
16:30-17:30, Friday, 15th July 2022

API design in C++ is harder than in other languages, as the lifetime of the arguments and return value shall be considered carefully. While it gives programmers the full power in expressing their intent, it raises all sorts of concerns that should be considered. In this talk we would analyze a very simple function: max, we would see that selecting the proper API is not as simple as it may seem and discuss several alternatives. The discussion would take us through lvalue, rvalue and forwarding references, the rules of moving from a local, variadic templates design, the differences between returning auto and decltype(auto) and C++20 constraints. Attendees may go back after this talk to their code looking for improving their API design making it less bug prone and more efficient.

API design
Variadic Templates
Reference Types

Amir Kirsh

C++ lecturer at the Academic College of Tel-Aviv-Yaffo and at Tel-Aviv University and Dev Advocate at Incredibuild. Previously the Chief Programmer at Comverse. Co-organizer of Core C++ conference and a member of the Israeli ISO C++ NB.