Peter Alexander:
void foo(ForwardRange Range)(Range r)
{
r.popBack();
}
And *immediately* get a type error without having to
instantiate it with a variety of different range types.
It's not an easy problem. To solve it the Rust language uses
typeclasses adapted from Haskell. But unlike the usual Haskell
compilers Rust doesn't use global type inferencing and it keeps
the C++-style monomorphization, so at run-time its generic
programming is as efficient as C++ generic programming.
I also hope Rust designers will take a look at this (Efficient
Dynamic Dispatch without Virtual Function Tables. The SmallEiffel
Compiler), an alternative to virtual tables. Maybe the D
front-end could do the same on request with a compilation switch
(with no changes in D language):
http://smarteiffel.loria.fr/papers/oopsla97.pdf
Bye,
bearophile