c++ - SFINAE overload choice for has or has not operator<<? -


consider these 2 functions:

template <class type,            class = typename std::enable_if</*has operator <<*/>::type> void f(std::ostream& stream, const type& value);  template <class type,            class... dummytypes,           class = typename std::enable_if<sizeof...(dummytypes) == 0>::type> void f(std::ostream& stream, const type& value, dummytypes...); 

as non-variadic overload has priority on variadic overload, want check whether type has operator<< std::ostream using std::enable_if in first version.

so should write instead of /*has operator <<*/ ?

the following should work

template <class type,            class = decltype(std::declval<std::ostream&>() << std::declval<type>())> void f(std::ostream& stream, const type& value) {     stream << value; } 

(note don't need use std::enable_if in case)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -