Skip to content

How to refactor this code ? Dimensionless and percentage #657

Answered by mpusz
Becheler asked this question in Q&A
Discussion options

You must be logged in to vote

In terms of usage, I find myself often wanting to "specialize" integral types, in terms of counting peas or salads (or in that case time_quanta) for readibility, but I also want to maintain their usage for incrementing counters and do some basic arithmetic.

This is a perfectly valid scenario. This is exactly what I propose above.

If you do not want to have convertibility with pure numbers you can introduce custom domain-specific units. You can find more details and inspiration in: https://isocpp.org/files/papers/P3045R4.html#user-defined-quantities-and-units.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Becheler
Comment options

@mpusz
Comment options

Answer selected by Becheler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants