Why does D not have generics?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Jan 12 22:57:36 UTC 2021


On Tuesday, 12 January 2021 at 22:53:39 UTC, jmh530 wrote:
>
> What about
>
> auto pop_second(T)(T* obj)
>     if (__traits(compiles, {
>             T input = T.init;
>             auto stack = input.as_StackConcept();
>         }))
> {
>     ...
> }

Yes, something like that! Except we wrap it up as 
hasStackConcept!T.

So then you can use the constraint "if(hasStackConcept!T)"



More information about the Digitalmars-d mailing list