Simultaneously existing a template function with std::enable_if and an ordinary template function

  c++, c++17, enable-if, sfinae, templates

I have a simple function:

template<class T>
typename std::enable_if_t<std::is_arithmetic_v<T>>
foo(T val) { }

I would like also to have another function with the same name:

template<class T>
void foo(T value) { }

I want to call the first function with arithmetic types and the second function for all other types. An idea I have is to change the second function into this:

template<class T>
typename std::enable_if_t<!std::is_arithmetic_v<T>>
foo(T val) { }

but is there a better way to achieve that?

Source: Windows Questions C++

LEAVE A COMMENT