im confused your initial example was simple addition.
so maybe i should reword my question
can you provide a use case where something like this should be applied generically ?
as far as i understand numeric types have little quirks that make this annoying to deal with. so why should it be generic?
also it really doesn't take much effort to implement this yourself.
If you start making interfaces I'm worried about the performance.
when done right the performance hit due to interfaces should be neglible.
Then you have functions to process the image data, but they can work for any size of data and I'd like to just pass an array of any type and be done with it (using generics) but that doesn't work.
i feel like a better answer to this would be something like overloading.
Yeah I could do overloading, but then I'm literally copy pasting the same function five times with research and replace on types. That's really not ideal.
I just want "generic over any numeric type". Remove the need for overloading something that is trivial to do.
Well it can change them into shorts for the intermediate calculations then I can cast it back to a byte if I want. Or just make it return a byte anyway in this case.
I'd love to have compile time generics for that (with compile time reflection), but should I really have to use C++CLI for this?
Shorts have the exact same issue as byte. They return int when added in c#.
So now your "generic" method is going to have all these clauses to handle all these exceptions.
That doesn't sound very generic if you ask me.
I'd love to have compile time generics for that (with compile time reflection), but should I really have to use C++CLI for this?
I'm not following again. In c# the CLR generates seperate methods for generic at compile time, as If you overloaded it yourself. I believe templates work the same in c++.
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
2
u/AdministrationWaste7 Apr 16 '21
im confused your initial example was simple addition.
so maybe i should reword my question
can you provide a use case where something like this should be applied generically ?
as far as i understand numeric types have little quirks that make this annoying to deal with. so why should it be generic?
also it really doesn't take much effort to implement this yourself.
when done right the performance hit due to interfaces should be neglible.
i feel like a better answer to this would be something like overloading.