{"id":27062872,"url":"https://github.com/doganulus/scalr","last_synced_at":"2025-04-05T15:27:18.193Z","repository":{"id":47082135,"uuid":"266115459","full_name":"doganulus/scalr","owner":"doganulus","description":"std::chrono inspired physical quantity/unit representation and manipulation library for C++11/14/17","archived":false,"fork":false,"pushed_at":"2023-11-29T12:59:40.000Z","size":712,"stargazers_count":2,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-02T01:07:22.566Z","etag":null,"topics":["cpp11","dimensional-analysis","physical-units","quantity","units"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doganulus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-22T13:19:49.000Z","updated_at":"2023-11-20T11:50:15.000Z","dependencies_parsed_at":"2023-11-29T13:29:46.280Z","dependency_job_id":"c4d0f46e-fb9b-43b4-9240-bffd1beee2cb","html_url":"https://github.com/doganulus/scalr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doganulus%2Fscalr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doganulus%2Fscalr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doganulus%2Fscalr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doganulus%2Fscalr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doganulus","download_url":"https://codeload.github.com/doganulus/scalr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247356722,"owners_count":20925885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp11","dimensional-analysis","physical-units","quantity","units"],"created_at":"2025-04-05T15:27:17.396Z","updated_at":"2025-04-05T15:27:18.186Z","avatar_url":"https://github.com/doganulus.png","language":"C++","readme":"# Scalr\nScalr is a `std::chrono` inspired C++ library for the representation and manipulation of scalar physical quantities and their units of measurements. \n\nScalr is a work in progress... \n\n## Features and goals\n\n* C++11/14/17 compatibility\n* Compile-time dimension analysis\n* User experience of popular `std::chrono` library\n* Shorter and more meaningful compilation errors --\u003e good to have \n* User-defined literals for units and std::cout support --\u003e good to have \n\n## Quick look\n\nScalr is based on the International System (SI) of Units starting with seven base dimensions. In the nutshell, Scalr provides a generic compile-time dimension/unit arithmetic as well as defines a facade for named quantities with `std::chrono::duration` style. Using Scalr, we define physical quantities as follows:\n\n```c++\n    scalr::duration\u003cintmax_t, std::ratio\u003c1\u003e\u003e secs(120); \n    scalr::speed\u003cdouble, std::ratio\u003c10, 36\u003e\u003e kphs(18.0);\n    scalr::length\u003cdouble, std::ratio\u003c1000\u003e\u003e dist(0.6);\n\n    CHECK(dist == (kph * secs)); // Pass\n```\n\nHowever, the compiler would complain if you make a dimensional mistake such as: \n```c++\n    static_assert(kms == (kph * secs)); // Fail\n```\n\nSuch compile-time guarantees and automatic (lazy) conversions between units are the reason why you should use Scalr.\n\nMoreover, a number of helper aliases is available for named units. For example, \n\n```c++\nusing hours = duration\u003cintmax_t, std::ratio\u003c3600\u003e\u003e;\nusing minutes = duration\u003cintmax_t, std::ratio\u003c60\u003e\u003e;\nusing seconds = duration\u003cintmax_t\u003e;\n\nusing meters_per_second = speed\u003cdouble, std::ratio\u003c1\u003e\u003e;\nusing kilometers_per_hour = speed\u003cdouble, std::ratio\u003c5, 18\u003e\u003e;\nusing miles_per_hour = speed\u003cdouble, std::ratio\u003c1397, 3125\u003e\u003e;\n\nusing kilohertz = frequency\u003cdouble, std::kilo\u003e;\n\nusing grams = mass\u003cdouble, std::ratio\u003c1, 1000\u003e\u003e;\n```\n\nThe source directory of named quantities and unit can be found [here](https://github.com/doganulus/scalr/tree/master/include/scalr/named_quantity) for the reference. \n\nFinally the [design document](https://github.com/doganulus/scalr/tree/master/docs/design.md) gives more information about the underlying structures and how it works.\n\n## Other Libraries\n\nThere are quite a number of similar libraries in existence. Some prominent ones are listed below, with my short comments.\n\n* [boost/units](https://www.boost.org/doc/libs/1_51_0/doc/html/boost_units.html) - Heavy design. I think `std::chrono` does a better job to handle time quantities.\n* [mputsz/units](https://github.com/mpusz/units) - New proposal for the future C++23 standard, not compatible with C++11/14/17. Besides I am not in favor of explicit systems as in Boost.\n* [PhysUnits-CT-Cpp11](https://github.com/martinmoene/PhysUnits-CT-Cpp11) - Close to Scalr in many ways but eagerly converts quantities to base units (unlike the lazy way in std::chrono::duration implementations, which has certain advantages).\n* [nholthaus/units](https://github.com/nholthaus/units) - Has some very nice features but not compatible with C++11. Besides representation type cannot be selected independently.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoganulus%2Fscalr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoganulus%2Fscalr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoganulus%2Fscalr/lists"}