Checking Functor Arguments in C++
summary
Templates that take user functors can silently accept unsafe implicit conversions; the solution uses a deleted conversion operator specialized for the types to check and a small templated conversion checker invoked inside a static_assert so overload resolution fails when an undesired conversion would occur. The compiler then produces an ambiguity/error pointing at the user call, preventing signed/unsigned surprises, avoids blaming library internals, and reliably stops compilation when conversions are wrong.
AI-written summary · about
related talks
06mConstraints not Satisfied
55mCustom Overload Sets and Inline SFINAE for Truly Generic Interfaces
54mTypical C++, But Why?
05mFighting Compiler warnings
01h 13mType safe C++ – LOL! :-)
22mOverloading: The Bane of All Higher-Order Functions
05mThe dangers of C-style casts
01h 01m“Template Normal Programming (part 2 of 2)"
