Back To Schedule

Overengineering max(a, b)

Mixed Comparison Functions, Common References, and Rust's Lifetime Annotations

14:30 - 16:00 Monday 28th April 2025 MT Lauder Seminar Room
Advanced
Generic/Metaprogramming

max is a function that returns the maximum of two numbers. While it seems simple on the surface, there are some nuances if you want to make max fully generic. For starters, what is max(-1, 1u) or max(lvalue, prvalue)?Let's go on a journey of overengineering max. We'll implement better mixed comparison functions, discuss common types and common references, wish for time machines to correct language semantics, and end up implementing Rust-style lifetime annotations using template metaprogramming and lots and lots of macros. The end result is a true work of art that we may or may not be using in actual production code.

View Slides

Jonathan Müller

Software EngineerLSEG

Jonathan is a Software Engineer at LSEG. There he develops low-latency market data feed handlers in C++ for high-frequency trading applications. Previously, he maintained think-cell’s core C++ libraries built around a custom range implementation.

He is also the chair of the std::ranges study group in the C++ standardization committee, a frequent speaker at conferences and universities, and the author of multiple open-source C++ libraries.