Embracing Trailing Return Types and `auto` Return SAFELY in Modern C++
summary
Compares trailing-return syntax vs omitted/auto return with concrete code: uses decltype(auto) to preserve value category, shows a units library and half_interval that compile and behave as expected, builds add_in returning a lambda and a thread_safe_invoke wrapper using mutexes and perfect forwarding, and demonstrates overload/substitution-failure differences that bite during refactoring. Enumerates restrictions (no virtual, no initializer_list, recursion/order sensitivity) and prescribes documentation, short functions, or explicit return types where deduction breaks insulation.
AI-written summary · about
chapters (20)
- 0:00Introduction
- 2:30Trailing Return Types
- 8:32Decotype
- 11:38Use Cases
- 16:05Auto Return
- 20:25Template parameter type deduction
- 26:21Conversion operator
- 28:50Syntax limitations
- 30:37Decotype Auto
- 32:36Decorating Auto
- 37:48Half Interval
- 41:01Mutex Lock
- 43:03Pitfalls
- 44:39Documentation
- 49:08Mitigation Strategy
- 50:29recursive factorial
- 51:22two different templates
- 52:25you get the fallback
- 54:48use it with caution
- 55:28Questions








