{"id":13419863,"url":"https://github.com/foonathan/type_safe","last_synced_at":"2025-05-15T12:03:40.437Z","repository":{"id":11793100,"uuid":"70328518","full_name":"foonathan/type_safe","owner":"foonathan","description":"Zero overhead utilities for preventing bugs at compile time","archived":false,"fork":false,"pushed_at":"2024-09-12T19:34:27.000Z","size":849,"stargazers_count":1573,"open_issues_count":6,"forks_count":121,"subscribers_count":64,"default_branch":"main","last_synced_at":"2025-04-11T19:13:21.036Z","etag":null,"topics":["c-plus-plus","type-safety"],"latest_commit_sha":null,"homepage":"https://type_safe.foonathan.net","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/foonathan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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},"funding":{"patreon":"foonathan","custom":["https://jonathanmueller.dev/support-me/"]}},"created_at":"2016-10-08T12:04:58.000Z","updated_at":"2025-04-11T14:43:07.000Z","dependencies_parsed_at":"2024-09-13T07:07:55.366Z","dependency_job_id":null,"html_url":"https://github.com/foonathan/type_safe","commit_stats":{"total_commits":373,"total_committers":27,"mean_commits":"13.814814814814815","dds":0.5683646112600536,"last_synced_commit":"3612e2828b4b4e0d1cc689373e63a6d59d4bfd79"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foonathan%2Ftype_safe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foonathan%2Ftype_safe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foonathan%2Ftype_safe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foonathan%2Ftype_safe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foonathan","download_url":"https://codeload.github.com/foonathan/type_safe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"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":["c-plus-plus","type-safety"],"created_at":"2024-07-30T22:01:22.047Z","updated_at":"2025-05-15T12:03:40.360Z","avatar_url":"https://github.com/foonathan.png","language":"C++","readme":"# type_safe \n\n![Project Status](https://img.shields.io/endpoint?url=https%3A%2F%2Fwww.jonathanmueller.dev%2Fproject%2Ftype_safe%2Findex.json)\n![Build Status](https://github.com/foonathan/type_safe/workflows/Main%20CI/badge.svg)\n\ntype_safe provides zero overhead abstractions that use the C++ type system to prevent bugs.\n\n\u003e Zero overhead abstractions here and in following mean abstractions that have no cost with optimizations enabled,\n\u003e but may lead to slightly lower runtime in debug mode,\n\u003e especially when assertions for this library are enabled.\n\nThe library features cannot really be explained in the scope of this readme,\nI highly suggest that you check out [the first](https://www.foonathan.net/2016/10/type-safe/) and [second blog post](https://www.foonathan.net/2016/10/strong-typedefs/) and the examples.\n\n## Features\n\n### Improved built-in types\n\n* `ts::integer\u003cT\u003e` - a zero overhead wrapper over a built-in integer type\n    * no default constructor to force meaningful initialization\n    * no \"lossy\" conversions (i.e. from a bigger type or a type with a different signedness)\n    * no mixed arithmetic with floating points or integer types of a different signedness\n    * no mixed comparison with floating points\n    * over/underflow is undefined behavior in release mode - even for `unsigned` integers,\n      enabling compiler optimizations\n* `ts::floating_point\u003cT\u003e` - a zero overhead wrapper over a built-in floating point\n    * no default constructor to force meaningful initialization\n    * no \"lossy\"  conversion (i.e. from a bigger type)\n    * no \"lossy\" comparisons\n    * no mixed arithmetic/comparison with integers\n* `ts::boolean` - a zero overhead wrapper over `bool`\n    * no default constructor to force meaningful initialization\n    * no conversion from integer values\n    * no arithmetic operators\n* aliases like `ts::uint32_t` or `ts::size_t` that are either wrapper or built-in type depending on macro\n* literal operators for those aliases like `342_u32` or `0_usize`\n\n### Vocabulary types\n\n* `ts::object_ref\u003cT\u003e` - a non-null pointer\n* `ts::index_t` and `ts::distance_t` - index and distance integer types with only a subset of operations available\n* `ts::array_ref\u003cT\u003e` - non-null reference to contigous storage\n* `ts::function_ref\u003cT\u003e` - non-null reference to a function\n* `ts::flag` - an improved flag type, better than a regular `bool` or `ts::boolean`\n* `ts::flag_set\u003cEnum\u003e` - a set of flags\n* `ts::output_parameter\u003cT\u003e` - an improved output parameter compared to the naive lvalue reference\n\n### Optional \u0026 Variant\n\n* `ts::basic_optional\u003cStoragePolicy\u003e` - a generic, improved `std::optional` that is fully monadic,\n  also `ts::optional\u003cT\u003e` and `ts::optional_ref\u003cT\u003e` implementations\n* `ts::compact_optional` implementation for no space overhead optionals\n* `ts::basic_variant\u003cVariantPolicy, Types...\u003e` - a generic, improved `std::variant`, also `ts::variant` and `ts::fallback_variant` implementations\n\n### Type safe building blocks\n\n* `ts::constrained_type\u003cT, Constraint, Verifier\u003e` - a wrapper over some type that verifies that a certain constraint is always fulfilled\n    * `ts::constraints::*` - predefined constraints like `non_null`, `non_empty`, ...\n    * `ts::tagged_type\u003cT, Constraint\u003e` - constrained type without checking, useful for tagging\n    * `ts::bounded_type\u003cT\u003e` - constrained type that ensures a value in a certain interval\n    * `ts::clamped_type\u003cT\u003e` - constrained type that clamps a value to ensure that it is in the certain interval\n* `ts::strong_typedef` - a generic facility to create strong typedefs more easily\n* `ts::deferred_construction\u003cT\u003e` - create an object without initializing it yet\n\n## Installation\n\nHeader-only, just copy the files in your project.\nYou need to add the type_safe `include` directory to your include path as well as make [debug_assert.hpp](https://github.com/foonathan/debug_assert) available.\nThe repository is included.\nYou also need to enable C++11.\n\nBehavior can be customized with the following macros:\n\n* `TYPE_SAFE_ENABLE_ASSERTIONS` (default is `1`): whether or not assertions are enabled in this library\n* `TYPE_SAFE_ENABLE_WRAPPER` (default is `1`): whether or not the typedefs in `type_safe/types.hpp` use the wrapper classes\n* `TYPE_SAFE_ARITHMETIC_POLICY` (`ub`/`checked`/`default`, default is `ub`): whether under/overflow in the better integer types is UB, an exception, or the default behavior\n\nIf you're using CMake there is the target `type_safe` available after you've called `add_subdirectory(path/to/type_safe)`.\nSimply link this target to your target and it will setup everything automagically.\nFor convenience the macros are also mapped to CMake options of the same name.\n\n## Documentation\n\nYou can find the full documentation generated by [standardese](https://github.com/standardese/standardese) [here](https://type_safe.foonathan.net/).\n\n## Acknowledgements\n\nThis project is greatly supported by my [patrons](https://patreon.com/foonathan).\nIn particular thanks to the individual supporters:\n\n* Mark Atkinson\n* Reiner Eiteljörge \n\nAnd big thanks to the main contributors as well:\n\n* Johel Ernesto Guerrero Peña [@johelegp](https://github.com/johelegp)\n    \n","funding_links":["https://patreon.com/foonathan","https://jonathanmueller.dev/support-me/"],"categories":["TODO scan for Android support in followings","C++","Containers and Algorithms"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoonathan%2Ftype_safe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoonathan%2Ftype_safe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoonathan%2Ftype_safe/lists"}