C++ units-of-measurement

Open-source C++ projects categorized as units-of-measurement

Top 3 C++ units-of-measurement Projects

units-of-measurement
  1. mp-units

    The quantities and units library for C++

    Project mention: Python type hints may not be not for me in practice | news.ycombinator.com | 2024-11-27

    I suspect C++ still comes the closest to what you’re asking for today, at least among mainstream programming languages.

    Matrix dimensions are certainly doable, for example, because templates representing mathematical types like matrices and vectors can be parametrised by integers defining their dimension(s) as well as the type of an individual element.

    You can also use template wizardry to write libraries like mp-units¹ or units² that provide explicit representations for numerical values with units. You can even get fancy with user-defined literals so you can write things like 0.5_m and have a suitably-typed value created (though that particular trick does get less useful once you need arbitrary compound units like kg·m·s⁻²).

    Both of those are fairly well-defined problems and the solutions available do provide a good degree of static checking at compile time.

    IMHO, the range question is the trickiest one of your three examples, because in real mathematical code there are so many different things you might want to constrain. You could define a parametrised type representing open or closed ranges of integers between X and Y easily enough, but how far down the rabbit hole do you go? Fractional values with attached precision/error metadata? The 572 specific varieties of matrix that get defined in a linear algebra textbook, and which variety you get back when you compute a product of any two of them?

    ¹ https://mpusz.github.io/mp-units/

    ² http://nholthaus.github.io/units/

  2. CodeRabbit

    CodeRabbit: AI Code Reviews for Developers. Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.

    CodeRabbit logo
  3. au

    A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience. (by aurora-opensource)

  4. konverter

    Flexible engineering and scientific unit converter.

NOTE: The open source projects on this list are ordered by number of github stars. The number of mentions indicates repo mentiontions in the last 12 Months or since we started tracking (Dec 2020).

C++ units-of-measurement discussion

Log in or Post with

C++ units-of-measurement related posts

  • Looking for a metric converter

    1 project | /r/foss | 1 Mar 2023

Index

What are some of the best open-source units-of-measurement projects in C++? This list will help you:

# Project Stars
1 mp-units 1,177
2 au 358
3 konverter 1

Sponsored
CodeRabbit: AI Code Reviews for Developers
Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.
coderabbit.ai