Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Which can't be achieved in most OOP languages that I know of, except for Scala and that's because Scala has "implicit parameters" which are equivalent to Haskell's type classes.

C++ can do that with template specialization.



I didn't know that, but it doesn't surprise me, seems to me like C++ templates are like their own language grown within C++ and can do lots of crazy things.


It is fairly straightforward, created a pastebin showing how it can be done, you can also make it check that it is implemented at compile time but the logic around that is a bit iffy:

https://pastebin.com/DiFh4GuM




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: