Why was std::bit_cast added, if reinterpret_cast could do the same?

Well, there is one obvious reason: because it wouldn’t do everything that bit_cast does. Even in the C++20 world where we can allocate memory at compile time, reinterpret_cast is forbidden in constexpr functions. One of the explicit goals of bit_cast is to be able to do these sorts of things at compile-time: Furthermore, it is … Read more

Default value for typescript type alias

You cannot add default values directly to a type declaration. You can do something like this instead: // Declare the type export type SomeType = { typename: string; strength: number; radius: number; some_func: Function; some_other_stat: number; } // Create an object with all the necessary defaults const defaultSomeType = { some_other_stat: 8 } // Inject … Read more