Skip to content

Conversion and reinterpreting #192

@ktbarrett

Description

@ktbarrett

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions