3 ms·
Closures are simpler, and therefore less cumbersome for 90% of the use cases. I prefer this compromise over the other. Also, I'm not sure I get this "type era
by loup-vaillant 12y ago
Closures are simpler, and therefore less cumbersome for 90% of the use cases. I prefer this compromise over the other.
Also, I'm not sure I get this "type erasure" business. In ML languages, there is no such erasure. I guess you need this erasure because the language doesn't support parametric polymorphism to begin with? I'm thinking about Java, which hacked generics after the fact, and maintained backward compatibility through type erasure.
In C++, there are few type erasures. Generally, when we want a function to receive a closure, we write it like this (minus dark corner I have missed):
template <typename T, typename E>
for_each(T functor, vector<E>);
No base class in sight there, just lots of duplicated object code. (Which is better is left as an exercise to the reader.)