Conditions for using `std::enable_if`

Back to std::enable_if: std::enable_if works through the principle of substitution failure is not an error (SFINAE) For SFINAE to kick in it has to be used on a (member) function template and it has to be dependent on a template parameter. Consider the function: std::enable_…

Simple std::enable_if example

Consider the following function: int negate(int i) { // (1) return -i; } and the following function template: template<class F> typename F::result_type negate(F const& f) { // (2) return -f(); } where F is some function object type (so that a member type F::result_type exists). Let…

Remastered std::enable_if

While we wait for Concept Lite to find its way into the standard, here's a nice way of using SFINAE.…