From Jason Turner
Watch on YouTube

Summary

In this episode, Jason explores a significant improvement in C++23 that fixes lifetime issues with range-based for loops. He demonstrates how C++20 and earlier had dangerous lifetime issues when using temporaries in range-based for loops, where references to data inside temporary objects would dangle. C++23 (standardized via proposals P2644R1 and P2718R0) extends the lifetime of temporaries for the entire duration of the range-based for loop, eliminating a whole class of potential bugs. The episode shows the fix working correctly even with multiple layers of temporaries and references.

Resources

Tags