Skip to content

Compile-time units resolution #2

@altavir

Description

@altavir

Use compile-time units resolution in order to avoid number boxing.

The basic idea is the following:

  • Make Measurement an interface. And keep the implementation you already have for dynamic units.
  • Add an inline Measurement implementation like this:
inline class InlineMeasurement(<U: Units>(val value: Double): Measurement<U>
  • Add a resolver: inline fun <reified U:Units> resolveUnits(): Units and use it to load Units object when it is needed. The resolver could work in different ways. The simplest way is to load objectInstance from reflects.

Both implementations could be used in different cases: boxing one in cases, when the Units are dynamic, inline when you can infer everything in compile-time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions