{"id":13730246,"url":"https://github.com/foonathan/tiny","last_synced_at":"2025-06-20T16:40:16.277Z","repository":{"id":74810280,"uuid":"144462094","full_name":"foonathan/tiny","owner":"foonathan","description":"low-level library for minimizing the size of your types","archived":false,"fork":false,"pushed_at":"2019-10-02T17:57:50.000Z","size":150,"stargazers_count":109,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-04T02:09:23.623Z","etag":null,"topics":["bit-twiddling","cplusplus","tombstone"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foonathan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2018-08-12T11:44:35.000Z","updated_at":"2024-05-06T13:02:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"0c102450-09bf-4031-87ad-08d854a091ec","html_url":"https://github.com/foonathan/tiny","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/foonathan%2Ftiny","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foonathan%2Ftiny/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foonathan%2Ftiny/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foonathan%2Ftiny/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foonathan","download_url":"https://codeload.github.com/foonathan/tiny/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224197918,"owners_count":17271999,"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":["bit-twiddling","cplusplus","tombstone"],"created_at":"2024-08-03T02:01:12.150Z","updated_at":"2024-11-12T01:09:19.483Z","avatar_url":"https://github.com/foonathan.png","language":"C++","funding_links":["https://patreon.com/foonathan"],"categories":["C++"],"sub_categories":[],"readme":"# foonathan/tiny\n\n![Project Status](https://img.shields.io/endpoint?url=https%3A%2F%2Fwww.jonathanmueller.dev%2Fproject%2Ftiny%2Findex.json)\n[![Build Status](https://dev.azure.com/foonathan/tiny/_apis/build/status/foonathan.tiny)](https://dev.azure.com/foonathan/tiny/_build/latest?definitionId=3)\n\n\u003e Note: This project is currently WIP, no guarantees are made until an 0.1 release.\n\nThis project is a C++11 library for putting every last bit to good use.\nIt combines various techniques such as [`llvm::PointerIntPair`](http://llvm.org/doxygen/classllvm_1_1PointerIntPair.html), [tombstones](https://youtu.be/MWBfmmg8-Yo?t=2466) and (a custom implementation of) bitfields to write types that use as little bits as possible.\n\n**Important**: This library is a low-level implementation library.\nIt is meant for experienced C++ programmers who write foundational code, such as vocabulary types, containers etc.\nAs such, the types used by this library should *not* appear in interfaces directly.\nInstead they are implementation details of other types.\nThis is especially true for the `_impl` types such as `tiny::optional_impl`.\nProper vocabulary types are meant to be built on top of them.\n\n## Features\n\n### Foundations\n\n* `tiny::bit_view`: A view for a range of (possibly disjoint) bits.\n  This is a fundamental type used internally and for implementing some traits.\n* `tiny::enum_traits`: Traits to specify range of an `enum`.\n  Will be automatically implemented for enumerations with members such as `unsigned_count_`,\n  but can be specialized for own types.\n  They are required for exposing information about your enumerations.\n* `tiny::padding_traits`: Traits to specify padding bytes of your type.\n  They basically provide a `tiny::bit_view` to the bytes that are padding.\n  `tiny::padding_traits_aggregate` provides a semi-automatic implementation for aggregate types.\n\n### Tiny Types\n\nTiny types are types that are just a couple of bits in size.\nThey cannot be stored directly but instead in a storage type:\n\n* `tiny::tiny_storage`: Stores multiple tiny types tightly packed together (think bitfields).\n\n* `tiny::pointer_tiny_storage`: Stores tiny types in the alignment bits of a pointer.\n\n* `tiny::padding_tiny_storage`: Stores tiny types in the padding of another type.\n\nThe tiny types provided by this library:\n\n* `tiny::tiny_bool`: a `bool`\n* `tiny::tiny_int\u003cN\u003e`/`tiny::tiny_unsigned\u003cN\u003e`: `N` bit integers (where `N` is tiny)\n* `tiny::tiny_int_range\u003cMin, Max\u003e`: the specified integers\n* `tiny::tiny_enum\u003cE\u003e`: a tiny enumeration\n* `tiny::tiny_flag_set\u003cFlags\u003e`: a set of flags, i.e. multiple booleans with names\n\n### Tombstones\n\nOptional implementations like `std::optional\u003cT\u003e` need to have storage for `T` and a boolean indicating whether or not one is currently stored.\nDue to alignment and padding this can easily double the size beyond what is necessary.\n\nA *tombstone* is a special \"invalid\" value of a type, like a `nullptr` reference.\nIt can be used to indicate an empty optional without needing to store a boolean.\n\nThe `tiny::tombstone_traits` are a non-intrusive way of exposing tombstones without creating the ability to expose the invalid type states.\n\n### Vocabulary Implementation Helpers\n\nA space efficient optional implementation can be built on top of the tombstone traits.\nHowever, certain design decisions of such vocabulary types are somewhat controversial.\nSo instead of writing the full implementation, the library contains just the bare minimum.\nProper vocabulary types can be built on top.\n\nThose are:\n\n* `tiny::optional_impl`: a tombstone enabled and thus compact optional\n* `tiny::pointer_variant_impl`: a union of multiple pointer types using alignment bits to store the currently active pointer\n\n## FAQ\n\n**Q: Are those tricks standard conforming C++?**\n\nA: For the most part, yes:\nThe implementations are carefully crafted to avoid undefined behavior.\nHowever, I'm certainly relying on some implementation-defined behavior.\nFor example, the `tiny::pointer_tiny_storage` makes some assumptions about the integral representation of pointers that are not necessarily guaranteed,\nbut all implementations I'm aware of work that way.\nPlease let me know if yours don't!\n\n**Q: The tiny types behave weird when I use `auto`.**\n\nA: That's not a question, but yes.\nBy their very nature I cannot expose references to a stored tiny type.\nProxies are used instead, which interact poorly with `auto`.\nThis is an implementation limit I can't really do anything about.\n\n**Q: It breaks when I do this!**\n\nA: Don't do that. And file an issue (or a PR, I have a lot of other projects...).\n\n**Q: This is awesome!**\n\nA: Thanks. I do have a Patreon page, so consider checking it out:\n\n[![Patreon](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://patreon.com/foonathan)\n\n## Documentation\n\n\u003e A full reference documentation is WIP, look at the comments in the header files for now.\n\nAnnotated tutorial style examples can be found in [the example directory](example/).\n\n### Compiler Support\n\nThe library requires a C++11 compiler.\nCompilers that are being tested on CI:\n\n* Linux:\n    * GCC 5 to 8\n    * clang 4 to 7\n* MacOS:\n    * XCode 9 and 10\n* Windows:\n    * Visual Studio 2017\n\nIt only requires the following standard library headers:\n\n* `cstddef` and `cstdint`\n* `climits` and `limits`\n* `cstdlib` (for `std::abort`) and `cstring` (for `std::memcpy`)\n* `new` (for placement new only)\n* `type_traits`\n\nThe `debug_assert` library optionally requires `cstdio` for printing messages to `stderr`.\nDefining `DEBUG_ASSERT_NO_STDIO` disables that.\n\nIt does not use exceptions, RTTI or dynamic memory allocation.\n\n### Installation\n\nThe library is header-only and has only my [debug_assert](https://github.com/foonathan/debug_assert) library as dependency.\n\nIf you use CMake, `debug_assert` will be cloned automatically if not installed on the system.\nYou can use it with `add_subdirectory()` or install it and use `find_package(foonathan_tiny)`,\nthen link to `foonathan::foonathan_tiny` and everything will be setup automatically.\n\n## Planned Features\n\n* NaN floating point packing\n* More vocabulary type helpers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoonathan%2Ftiny","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoonathan%2Ftiny","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoonathan%2Ftiny/lists"}