2 ms·
> That sounds complicated to me, in 2019 with 25 years of C++ experience. std::cout << X; is not a generic, but on the project I just tested, if I substitute
by fluffything 7y ago
> That sounds complicated to me, in 2019 with 25 years of C++ experience.
std::cout << X;
is not a generic, but on the project I just tested, if I substitute X with a type that does not implement an appropriate operator<<, I get ~1000 suggestions in the overload set, many of which are generic operator<< that are templated on a `typename OStream`.
I personally find having to do overload resolution first on a 1000 function overload set containing generic and not generic functions, and then often having to actually instantiate a generic (doing template argument deduction, template instantiation, substitution-failure is not an error so the next overload might be picked, etc. etc. etc.) infinitely more complicated than "just" instantiating a generic.
- zozbot234 7y agoIndeed, type classes as found in languages like Haskell and Rust were first designed as a way to make overloading (aka "ad-hoc polymorphism") work more sensibly, and in a way that plays nice with generics/templates.