Universal/Forwarding References - A Key to More Modern C++
summary
Universal (template T&&) references enable one-template-parameter perfect forwarding via std::forward and reference-collapsing rules, and C++20 makes them essential for writing generic functions that accept both containers and views. Examples: implementing a call-through that forwards to foo, the range-based for expansion that uses an auto&& local to avoid copying or forcing const, and fixing view failures (drop/filter) that break when parameters are const. Use decltype(auto) to preserve returned value categories; using universal references resolves these issues.
AI-written summary · about
chapters (26)
- 0:00Modern C++ introduction
- 1:12C++ references basics
- 2:16Move semantics and rvalues
- 5:48Value categories in C++
- 9:17xvalues evolution
- 13:56How compilers handle values
- 16:03Rvalue reference problems
- 18:55Functions with rvalue refs
- 22:28Call-by-reference comparison
- 27:03Universal references core
- 31:20Universal vs forwarding
- 34:12Universal ref rules
- 36:40Benefits of universal refs
- 38:27Specifying universal refs
- 42:59Common universal ref mistakes
- 45:28Generic non-member functions
- 49:02Perfect forwarding
- 51:07decltype(auto) returns
- 56:48C++20 universal refs
- 57:51Range-based loops
- 1:02:22Practical universal refs
- 1:07:15C++20 ranges challenges
- 1:12:33Why const lvalue fails
- 1:19:57Solutions for views
- 1:22:03Summary and future
- 1:26:26Q&A
related talks
28mThe Many Shades of reference_wrapper
52mConcepts: The Future of Generic Programming
05mC++20 Lambdas: Familiar Template Syntax
06mReflecting Types in C++17/20
01h 36mImplementing Ranges and Views in C++
01h 14mReintroduction to Generic Programming for C++ Engineers
01h 29mHigher-order functions and function_ref
01h 00mInference in C++: The big picture
