Cursed C++ Casts
Join me for an October scary story as we try to find the identity of the scariest C++ cast.
The original inspiration for implementing public_cast came from here. I wrote my own version which is more modern and (IMHO) easier to understand, but I take no credit for the ingenuity (and devilishness) of the basic implementation technique.
https://github.com/libretro/bnes-libretro/blob/master/nall/public_cast.hpp
After uploading the video, I realized you could use a trait type, something like public_cast_traits, and specialize it with CxSecret to "store" the member pointer type (int C::*) once, and then just look it up inside public_cast, so you don't have to repeat it at every "call site." That's one possible solution for the part where I said to let me know if you have any ideas.
implicit_cast can be found in boost: https://www.boost.org/doc/libs/1_79_0/boost/implicit_cast.hpp
Other stuff:
evil floating point bit level hacking: https://en.wikipedia.org/wiki/Fast_inverse_square_root
Strict Aliasing: https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8
I use the amazing Manim library for animating these videos, and I edit them with Blender and Audacity.
https://www.manim.community/
https://www.blender.org/
https://www.audacityteam.org/