std::cout
is one of the poster children for operator overloading. While the choice of the actual operator ... is dubious ..., extensibility <<
massive compared to everything that came before it, and almost everything that came after it, too. Also, consider all the Matrix
and Vector
classes, iterators, function objects, all these classes with <
overloaded so that they can be the map
key or sorted as std::string
.
Polymorphism is quite simple. Think about what life will be like if you did not have parametric polymorphism in the form of patterns. Holy shit, it would be so bad. Do I repeat this container code for a new type, which is a terribly bad idea, or can I go with this garbage void*, size
, which cannot handle complex types and is completely unsafe? An interface like qsort
is not applicable either. Parametric polymorphism allows both code reuse and type safety.
Or dynamic polymorphism. std::function
cannot work without virtual functions and inheritance, and this is a pretty damn important thing. There are also built-in inheritance-based optimizations. This is useful when you need to handle different types interchangeably at runtime. In addition, there are many things that are effective dynamic polymorphisms, even if they are technically not. For example, every function that you call from the Windows API goes through a table of function pointers set by the dynamic linker. They are polymorphic with any implementation of those functions that correspond to the same interface. What would life be like without the operating system APIs? Unsuitable.
Puppy source share