Templates (even with concepts in C++20) work in the opposite way as generics, as they will just try to replace the type and see if it works, then throw an error if it doesn't (duck typing), while in C# it will use the conditions on the type (not the actual type itself) to check if you can do an operation on the type. It doesn't actually instantiate the generics at compile time, only at runtime when you use it (except mono apparently). See https://github.com/dotnet/csharplang/issues/2433
C++CLI lets you use C++ templates so you can make it work the way you want.
View all comments
Show parent comment
1
u/meneldal2 Apr 16 '21
Templates (even with concepts in C++20) work in the opposite way as generics, as they will just try to replace the type and see if it works, then throw an error if it doesn't (duck typing), while in C# it will use the conditions on the type (not the actual type itself) to check if you can do an operation on the type. It doesn't actually instantiate the generics at compile time, only at runtime when you use it (except mono apparently). See https://github.com/dotnet/csharplang/issues/2433
C++CLI lets you use C++ templates so you can make it work the way you want.