The Detection Idiom - a simpler way to SFINAE
summary
Explains a practical way to replace messy enable_if SFINAE with the detection idiom from the Library Fundamentals TS that uses void_t plus a hidden detector and utilities like is_detected / detected_t / detected_or. Shows concrete checks (nested type presence, size_type fallback, copy-assignment signature) implemented with decltype and declval, compiles at compile time, and simplifies many library traits; requires modern C++ (C++14-style templates) and the examples all compile as shown.
AI-written summary · about
chapters (13)
- 0:00Introduction and speaker background
- 2:43What is the detection idiom
- 8:58SFINAE and overload resolution
- 17:18Why detection idiom matters
- 21:11Simple example with nested types
- 23:24Practical example with size_type
- 26:05Void T and Nonesuch explained
- 31:54How detection idiom works
- 36:23Variations on detection
- 41:11Detecting expressions and member functions
- 45:27Detecting copy assignment
- 49:45Detected exact and convertible
- 51:09Using detection in SFINAE
related talks
06mNo Concepts Beyond This Point: The Detection Idiom
04mA Static Alternative to Virtual Functions, Using Expression SFINAE
01h 01mA Soupçon of SFINAE
05mSFINAE: Substitution Failure Is Not An Error
58mConcept Based Testing
51mModern techniques for keeping your code dry
06mLightning Talk: How Hard Can it be to SFINAE in C++03?
55mCustom Overload Sets and Inline SFINAE for Truly Generic Interfaces
