## About me * Canadian * Mechanical engineering degree * I like twisty puzzles  * Working in C++ for 4 years * On WG21 since 2023 * Run Winnipeg C++ Developers
## Lambdas * Introduced in C++11 * On the cutting edge of C++ features
"constexpr ALL the things!"
https://www.youtube.com/watch?v=HMB9oXFobJc
## How much can we do without...? * structs/classes * unions * functions
## Goals * Implement as much of the stdlib as possible * ... with minimal classes/structs, unions, functions * ... in C++23 * Determine the minimum number of "rule breaks" * Maintain C++'s semantics
## This talk is * A thought experiment * Scientific * A fun challenge, testing limits of lambdas * A 90-minute lightning talk * _Full of code you should not write!_
## Overview * History of C++ lambdas * Type traits and utilities * Classes by example - `unique_ptr` * More features
Type traits and utilities
[expr.prim.lambda.closure]/1
The type of a
lambda-expression
(which is also the type of the closure object)
is a unique, unnamed non-union class type
, called the
closure type
, whose properties are described below.
## Type traits and utilities * `integral_constant` * Query traits, like `is_same` * `type_identity` * Cast functions * Overloading
Classes by example
## Classes by example - `unique_ptr` * Data members * Data accessors, and member functions * Non-SMF constructors * Static members, e.g. typedefs * Copy and move * Destructors
More features
## More features * Propagating copy and move * `tuple` - member function template * `tuple` - equality operator * Reusable storage * Range-based for loop * Declaration and TUs * `main` function
Conclusion
Conclusion
Lambdas are very powerful in C++23!
except...
Lambda Restrictions
No implicit conversions, e.g. base class slicing
No member typedef
No compiler-selected overloading
No user-defined conversion functions
No user-defined implicit copy/move operations
No user-defined destructors
Limited template argument deduction
No directly extendable overload sets
No operator overloading
No array captures
No separating declaration and definition
No linking across TUs
## Unavoidable rule breaks * Struct template `type_identity` before C++26 * Struct `no_copy` * Struct template `dtor_wrapper` * Union template `variadic_union` * `main` function in hosted environment * ... others?
## Takeaways * The standard library is huge * Lambdas are versatile * Lambdas can replace most classes and functions * But not all * The standard library is _huge_ * Play around with code!