3 ms·
Going via the interface route that you described doesn't rescue C++ here. The thing that parametric polymorphism gives you is that the type system can ensure t
by eru 5y ago
Going via the interface route that you described doesn't rescue C++ here.
The thing that parametric polymorphism gives you is that the type system can ensure that your code is not doing anything with your values but pass them around. And you don't need to read nor trust any implementation code for that.
For what you describe you could still implement cosine for float, and 'not' for bools, and identity for char.
We don't want the class to implement certain semantics. We'd want an assurance that certain semantics are _not_ implemented (in some sense). We want an assurance that the code is forced to treat the value as an opaque black box.