{"id":19252741,"url":"https://github.com/tomaszrewak/strong_typedefs","last_synced_at":"2026-06-18T19:31:19.629Z","repository":{"id":211801755,"uuid":"729978647","full_name":"TomaszRewak/strong_typedefs","owner":"TomaszRewak","description":"A strong_typedef implementation for C++ with selective operator overloads.","archived":false,"fork":false,"pushed_at":"2023-12-11T17:01:32.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T16:53:16.627Z","etag":null,"topics":["cpp","header-only","library","operator-overloading","strongly-typed"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomaszRewak.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-10T23:17:16.000Z","updated_at":"2023-12-11T13:26:08.000Z","dependencies_parsed_at":"2023-12-11T00:25:29.095Z","dependency_job_id":"469f7071-bcdc-4512-bb35-aa116ecc4c5a","html_url":"https://github.com/TomaszRewak/strong_typedefs","commit_stats":null,"previous_names":["tomaszrewak/strong_typedefs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TomaszRewak/strong_typedefs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomaszRewak%2Fstrong_typedefs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomaszRewak%2Fstrong_typedefs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomaszRewak%2Fstrong_typedefs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomaszRewak%2Fstrong_typedefs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomaszRewak","download_url":"https://codeload.github.com/TomaszRewak/strong_typedefs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomaszRewak%2Fstrong_typedefs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34505419,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cpp","header-only","library","operator-overloading","strongly-typed"],"created_at":"2024-11-09T18:28:16.033Z","updated_at":"2026-06-18T19:31:19.600Z","avatar_url":"https://github.com/TomaszRewak.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## About\n\nA (yet another) `strong_typedef` implementation for C++.\n\n`strong_typedef`s allow you to create new types that are derived from existing ones, but are not implicitly convertible to them. This allows you to create types that are semantically different, but have the same underlying representation.\n\nUsing `strong_typedef`s helps in avoiding some common pitfalls, like accidentally adding a distance to a time or passing a weight to a function that expects a price (where all of those could be represented by a `double`).\n\nThis (single-header) library also provides a convenient way of defining common operators for your new types. You can express that it makes sense to multiply a price by a quantity, while preventing the multiplication of two prices.\n\n## Usage\n\nInclude the header file:\n\n```cpp\n#include \"strong_typedef.hpp\"\n```\n\nDefine your new types:\n\n```cpp\nusing price = strong_typedef::type\u003cdouble, struct price_tag\u003e;\nusing quantity = strong_typedef::type\u003cint, struct quantity_tag\u003e;\n```\n\nExpress which operations are allowed and what are their result types:\n\n```cpp\ntemplate \u003c\u003e\nstruct strong_typedef::operators\u003cprice, price\u003e    // price □ price\n{\n    using add = price;                            // price + price =\u003e price\n    using subtract = price;                       // price - price =\u003e price\n};\n\ntemplate \u003c\u003e\nstruct strong_typedef::operators\u003cprice, quantity\u003e // price □ quantity\n{\n    using multiply = price;                       // price * quantity =\u003e price\n    using divide = price;                         // price / quantity =\u003e price\n};\n\ntemplate \u003c\u003e\nstruct strong_typedef::operators\u003cprice\u003e           // □ price\n{\n    using minus = price;                          // - price =\u003e price\n};\n```\n\nYou can now use your new types:\n\n```cpp\nvoid use(price price, quantity quantity) { /**/ }\n\nint main()\n{\n    price p{1.0};\n    quantity v{3};\n\n    use(p, v);                           // OK\n    use(p * v, v);                       // OK\n    use(-p, v);                          // OK\n    use(price{1}, quantity{3});          // OK\n    use(p, quantity{p.get() + v.get()}); // OK, on your own risk\n\n    use(v, p);     // Compile-time error (cannot pass a price as a quantity and vice versa)\n    use(p + v, v); // Compile-time error (cannot add quantity to a price)\n    use(1, 3);     // Compile-time error (cannot implicitly convert between a number and price/quantity)\n}\n```\n\nYou can retrieve the internal value using the `get()` method:\n\n```cpp\nprice p{1.0};\n\ndouble d = p.get();\n```\n\nThe list of supported operators is:\n\n```cpp\ntemplate \u003cclass In1, class In2 = void\u003e\nstruct strong_typedef::operators\n{\n    // For strong_typedef::operators\u003cIn1, In2\u003e\n    using add = _operator_undefined;\n    using subtract = _operator_undefined;\n    using multiply = _operator_undefined;\n    using divide = _operator_undefined;\n    using modulo = _operator_undefined;\n    using equal = _operator_undefined;\n    using not_equal = _operator_undefined;\n    using less = _operator_undefined;\n    using less_equal = _operator_undefined;\n    using greater = _operator_undefined;\n    using greater_equal = _operator_undefined;\n    using logical_and = _operator_undefined;\n    using logical_or = _operator_undefined;\n\n    // For strong_typedef::operators\u003cIn1\u003e\n    using plus = _operator_undefined;\n    using minus = _operator_undefined;\n    using logical_not = _operator_undefined;\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomaszrewak%2Fstrong_typedefs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomaszrewak%2Fstrong_typedefs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomaszrewak%2Fstrong_typedefs/lists"}