lately I started to dig deeper into templates and SFINEA.
In my project I was able to use SFINEA to do basically what I want.
But there is one exception.
I want to enable a function only if operator<<(ostream, Type) is available. I want it for exactly that type, not for any implicit conversion.
Below you find some sample C++ (17) code, that works. But in my project
I do not want it to work. Operator<< is not available for foo.
template<typename T>
struct abc // I have no idea what to call this sort of thing.
{
operator T() const;
};
template <typename T>
struct detector<T, std::void_t<
std::enable_if_t
<
std::is_same_v
<
std::ostream,
std::remove_reference_t
<
decltype(operator<<(std::declval<std::ostream>(), std::declval<abc<T>>()))
>
>
>>> : std::true_type
{
};
I think this should work because the compiler won't do more than one implicit conversion. Forcing an implicit conversion to T would hence disable implicit conversions from T.