How to detect if a function exists?
With declaration of
template<typename From, typename To> To convert(const From& from);
Your traits
template<typename From, typename To>
struct IsConvertible
would always detect presence of convert
function.
One way to fix it is overloads and/or SFINAE:
template <typename> struct Tag{};
int convertImpl(tag<int>, const std::string& from);
float convertImpl(tag<float>, const std::string& from);
// overloads ...
template<typename From, typename To>
auto convert(const From& from)
-> decltype(convertImpl(tag<To>{}, from))
{
return convertImpl(tag<To>{}, from);
}