Why does D not have generics?

Paul Backus snarwin at gmail.com
Tue Jan 12 17:16:19 UTC 2021


On Tuesday, 12 January 2021 at 17:12:11 UTC, Ola Fosheim Grøstad 
wrote:
> On Tuesday, 12 January 2021 at 16:57:43 UTC, Q. Schroll wrote:
>> For example, if you call T.method(), but no constraint says 
>> that T.method() exists, the compiler rejects the code. On the 
>> other hand, in C++ or D, if you call T.method() in a template 
>> and only test types that happen to have method(), everything 
>> is good between friends (Andrei's quote).
>
> But I don't quite see how this is different from C++ concepts, 
> which basically is better syntax for testing traits of types 
> provided through parameters/methods.

C++ concepts, as far as I'm aware, don't cause templates to be 
checked for conformance prior to instantiation--which is what's 
being asked for here. For that, you'd need something more like 
Rust's traits.


More information about the Digitalmars-d mailing list