Skip to content

Conversation

@prehner
Copy link
Contributor

@prehner prehner commented Dec 11, 2025

Two major advantages

  • Better readable error messages. The type shows up as something like Quantity<_, SIUnit<3, 2, -1, 0, 0, 0, 0>> rather than the typenum gibberish. Not completely self explanatory, but should be much easier to spot errors.
  • METER.powi::<P2>() becomes METER.powi::<2>(), so no need to import the obscure typenum::P2

Disadvantage

  • This means having to implement addition and subtraction for the units by hand, which is of course rather trivial, but also a lot of boilerplate. Right now I implemented it only for exponents of base units from -6 to 6, but could be increased rapidly if necessary.

Once const_generics can be used in operators the boilerplate can be simplified a lot without even breaking the code (I think).

@prehner prehner force-pushed the consts_instead_of_typenum branch from 2dee8bc to 357b4b8 Compare December 11, 2025 13:12
@prehner prehner merged commit 61afa50 into master Jan 6, 2026
21 checks passed
@prehner prehner deleted the consts_instead_of_typenum branch January 6, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants