What are they?
In this library there are two ways to change a value of one type to another type:
- "conversions" which convert by value
- "reinterprets" which convert by representation
Conversions may not be trivial, reinterprets are by definition trivial. Conversions are copies and thus can work on const variables. Reinterprets construct objects by moving the objects implementation into an object of a new type. Conversions can work on any two types as long as a singular conversion is possible. Reinterprets can only work between related types.
What does that look like?
Conversions will be of the form to_{DestinationType}(const FromType &) and reinterprets will be of the form as_{DestinationType}(FromType&&).
We can possibly use this to generalize this to to<DestinationType>(const FromType &) and as<DestinationType>(FromType&&) for maximally generic code, if that ends up being useful.
What types can be reinterpreted? What are the implications?
Reinterpret will mostly be limited in this library to BitArray, Signed, Unsigned, Sfixed, Ufixed and Float, as they will all, ideally, use the same implementation under the hood as they are all essentially bit-arrays under the hood. This may be GMP types, it may just be int64_t, or maybe a specialized mix of multiple data type. Regardless of which implementation they use, they will all need to make the same decisions about implementation for the given data size to prevent issues with reimplementation.
What are they?
In this library there are two ways to change a value of one type to another type:
Conversions may not be trivial, reinterprets are by definition trivial. Conversions are copies and thus can work on const variables. Reinterprets construct objects by moving the objects implementation into an object of a new type. Conversions can work on any two types as long as a singular conversion is possible. Reinterprets can only work between related types.
What does that look like?
Conversions will be of the form
to_{DestinationType}(const FromType &)and reinterprets will be of the formas_{DestinationType}(FromType&&).We can possibly use this to generalize this to
to<DestinationType>(const FromType &)andas<DestinationType>(FromType&&)for maximally generic code, if that ends up being useful.What types can be reinterpreted? What are the implications?
Reinterpret will mostly be limited in this library to
BitArray,Signed,Unsigned,Sfixed,UfixedandFloat, as they will all, ideally, use the same implementation under the hood as they are all essentially bit-arrays under the hood. This may be GMP types, it may just beint64_t, or maybe a specialized mix of multiple data type. Regardless of which implementation they use, they will all need to make the same decisions about implementation for the given data size to prevent issues with reimplementation.