Custom Overload Sets and Inline SFINAE for Truly Generic Interfaces
summary
Shows how C++17 features (void_t, template deduction guides, invoke, constexpr if, decltype(auto) on lambdas) let code pick the first compilable option, pick the best overload, or test validity of expressions without heavy boilerplate. Builds a validator/is_valid utility that makes inline SFINAE work via lambda return-type deduction, an overload_sequence that chooses the first callable that compiles (demonstrated with element_count selecting size, distance, or 1), and a type_selector that picks the first type making expressions valid. Works on Clang; deduction-guide trick currently breaks on some GCC cases; overload_set can’t handle final classes or unions yet.
AI-written summary · about
chapters (8)
- 0:00Introduction and motivation
- 7:43SFINAE limitations and challenges
- 13:53Inline SFINAE with lambdas
- 23:53Overload sequences for ranked calls
- 31:51Overload sets for best match
- 42:15Understanding callable types
- 48:53Type selection with expressions
- 51:56Summary and conclusions
related talks
01h 05mDon’t Get Overloaded by C++ Overload Sets
51mModern techniques for keeping your code dry
01h 00mInference in C++: The big picture
01h 03mHigher order functions for ordinary C++ developers
57mIntroduction to C++ Template Metaprogramming
01h 01mA Soupçon of SFINAE
49mC++17 Features (part 1 of 2)
01h 35mC++20 – My Favourite Code Examples
