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

Amir Kirsh

60 minute session
14:00-15:00, Thursday, 7th 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.