How can I write this function shorter?template<typename U, typename = typename std::enable_if<std::is_fundamental<U>::value>::type,    typename = typename std::enable_if<!std::is_same<char, U>::value>::type,    typename = typename std::enable_if<!std::is_same<void, U>::value>::type>void multiply(U&& u){};I want exclude several type like void or char, which don't must be number. I wrote code like this, but I think, that is better solution. (code of course is correctly)
SFINAE with several condition [Refactoring]
c++;c++14;c++17;sfinae
Seems short enough to me.It's impossible to know how to refactor any code without first knowing what it is supposed to do. All we know about this no-op function is that you want [to] exclude several type[s] like void or char. How many types? Which types? Why?The obvious shortening istemplate<class U, class = std::enable_if_t<std::is_fundamental_v<U>>,    class = std::enable_if_t<!std::is_same_v<char, U> && !std::is_same_v<void, U>>>void multiply(U&&) {}i.e. just remove all the superfluous ::type and ::value, and replace typename by class because it's shorter (and you did ask for us to make it shorter!).Your naming the function multiply implies that maybe what you want istemplate<class U>auto multiply(U&& u) -> decltype(u*u, void()) {}Your comments about don't must be number imply that maybe what you want istemplate<class U, class = std::enable_if_t<std::is_arithmetic_v<U>>>void multiply(U&&) {}But we really can't know for sure unless you tell us what the code is supposed to do.