Why does D not have generics?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue Jan 12 17:43:39 UTC 2021
On Tuesday, 12 January 2021 at 17:32:17 UTC, Paul Backus wrote:
> template<MyConcept T>
> void fun(T t) { t.bar(); }
>
> In Java or Rust, the above would be a compile-time error.
Ok, I get what you say. Concepts is more for library implementors
than applications, so it is assumed the library implementor knows
what he is doing, and the focus is on putting restrictions on
library usage.
But you can do that in C++ to some extent. You can remove members
from a declaration, even though they are present in the
definition. Thanks to header files and reinterpret casting. There
is a lot of stuff you can do in C++ (but not really recommended).
More information about the Digitalmars-d
mailing list