{"id":15047260,"url":"https://github.com/martinmoene/byte-lite","last_synced_at":"2025-04-10T00:50:58.126Z","repository":{"id":53745035,"uuid":"86210857","full_name":"martinmoene/byte-lite","owner":"martinmoene","description":"byte lite - A C++17-like byte type for C++98, C++11 and later in a single-file header-only library","archived":false,"fork":false,"pushed_at":"2025-03-23T06:44:01.000Z","size":140,"stargazers_count":53,"open_issues_count":0,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-10T00:50:54.609Z","etag":null,"topics":["byte","byte-implementations","cpp17","cpp98","header-only","no-dependencies","single-file"],"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/martinmoene.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-03-26T05:52:21.000Z","updated_at":"2025-03-23T06:44:06.000Z","dependencies_parsed_at":"2024-06-01T16:08:47.967Z","dependency_job_id":"771b8b6a-f818-4a5d-a58c-e9bf765e0160","html_url":"https://github.com/martinmoene/byte-lite","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fbyte-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fbyte-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fbyte-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fbyte-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinmoene","download_url":"https://codeload.github.com/martinmoene/byte-lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137999,"owners_count":21053775,"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":["byte","byte-implementations","cpp17","cpp98","header-only","no-dependencies","single-file"],"created_at":"2024-09-24T20:55:50.781Z","updated_at":"2025-04-10T00:50:58.080Z","avatar_url":"https://github.com/martinmoene.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# byte lite: A single-file header-only C++17-like byte type for C++98, C++11 and later\n\n[![Language](https://img.shields.io/badge/C%2B%2B-98/11/14/17-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization) [![License](https://img.shields.io/badge/license-BSL-blue.svg)](https://opensource.org/licenses/BSL-1.0) [![Build Status](https://github.com/martinmoene/byte-lite/actions/workflows/ci.yml/badge.svg)](https://github.com/martinmoene/byte-lite/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/gpmw4gt271itoy2n?svg=true)](https://ci.appveyor.com/project/martinmoene/byte-lite) [![Version](https://badge.fury.io/gh/martinmoene%2Fbyte-lite.svg)](https://github.com/martinmoene/byte-lite/releases) [![download](https://img.shields.io/badge/latest-download-blue.svg)](https://raw.githubusercontent.com/martinmoene/byte-lite/master/include/nonstd/byte.hpp) [![Conan](https://img.shields.io/badge/on-conan-blue.svg)](https://conan.io/center/byte-lite) [![Vcpkg](https://img.shields.io/badge/on-vcpkg-blue.svg)](https://vcpkg.link/ports/byte-lite) [![Try it online](https://img.shields.io/badge/on-wandbox-blue.svg)](https://wandbox.org/permlink/6wTFn0svYP4dQYhV) [![Try it on godbolt online](https://img.shields.io/badge/on-godbolt-blue.svg)](https://godbolt.org/z/xjekHR)\n\n**Contents**\n- [Example usage](#example-usage)\n- [In a nutshell](#in-a-nutshell)\n- [License](#license)\n- [Dependencies](#dependencies)\n- [Installation](#installation)\n- [Synopsis](#synopsis)\n- [Features](#features)\n- [Reported to work with](#reported-to-work-with)\n- [Building the tests](#building-the-tests)\n- [Other implementations of byte](#other-implementations-of-byte)\n- [Notes and References](#notes-and-references)\n- [Appendix](#appendix)\n\n\nExample usage\n-------------\n\n```Cpp\n#include \"nonstd/byte.hpp\"\n\n#include \u003ccassert\u003e\n\nusing namespace nonstd;\n\nint main()\n{\n    byte b1 = to_byte( 0x5a );  // to_byte() is non-standard, needed for pre-C++17\n    byte b2 = to_byte( 0xa5 );\n\n    byte r1 = b1 ^ b2; assert( 0xff == to_integer( r1 ) );  // not (yet) standard, needs C++11\n    byte r2 = b1 ^ b2; assert( 0xff == to_integer\u003cunsigned int\u003e( r2 ) );\n}\n```\n\n### Compile and run\n\n```\nprompt\u003e g++ -std=c++11 -Wall -I../include -o 01-basic 01-basic.cpp \u0026\u0026 01-basic\n```\n\nOr to run with [Buck](https://buckbuild.com/):\n\n```\nprompt\u003e buck run example:01-basic\n```\n\nIn a nutshell\n-------------\n**byte lite** is a single-file header-only library to provide a [C++17-like distinct byte type](http://en.cppreference.com/w/cpp/types/byte) for use with C++98 and later.\n\n**Features and properties of byte lite** are are ease of installation (single header), freedom of dependencies other than the standard library.\n\n**A limitation of byte lite** is that you need to use function `to_byte(v)` to construct a `byte` from an integral value `v`, when C++17's relaxation of the enum value construction rule is not available.\n\nLicense\n-------\n*byte lite* is distributed under the [Boost Software License](https://github.com/martinmoene/XXXX-lite/blob/master/LICENSE.txt).\n\n\nDependencies\n------------\n*byte lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).\n\n\nInstallation\n------------\n*byte lite* is a single-file header-only library. Put `byte.hpp` in the [include](include) folder directly into the project source tree or somewhere reachable from your project.\n\n\nSynopsis\n--------\n\n**Contents**\n- [Types in namespace nonstd](#types-in-namespace-nonstd)\n- [Algorithms for *byte lite*](#algorithms-for-byte-lite)\n- [Configuration macros](#configuration-macros)\n\n### Types in namespace nonstd\n\n| Purpose            | Type                | Std     | Notes  |\n|--------------------|:--------------------|:-------:|:-------|\n| Distinct byte type | enum class **byte** | \u003e=C++17 | \u0026nbsp; |\n| \u0026nbsp;             | struct **byte**     | \u003c C++17 | \u0026nbsp; |\n\n### Algorithms for *byte lite*\n\n| Kind              | Std     | Function | Result |\n|-------------------|:-------:|----------|--------|\n| Shift-assign      |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u003c\u003c=**( byte \u0026 b, IntegerType shift ) noexcept | left-shifted b |\n| \u0026nbsp;            |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u003e\u003e=**( byte \u0026 b, IntegerType shift ) noexcept | right-shifted b |\n| Shift             |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte **operator\u003c\u003c**( byte b, IntegerType shift ) noexcept | left-shifted byte |\n| \u0026nbsp;            |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte **operator\u003e\u003e**( byte b, IntegerType shift ) noexcept | right-shifted byte |\n| Bitwise-op-assign |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u0026#166;=**( byte \u0026 l, byte r ) noexcept | bitwise-or-ed b |\n| \u0026nbsp;            |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u0026amp;=**( byte \u0026 l, byte r ) noexcept | bitwise-xor-ed b |\n| \u0026nbsp;            |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u0026Hat;=**( byte \u0026 l, byte r ) noexcept | bitwise-and-ed b |\n| Bitwise-op        |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u0026#166;**( byte l, byte r ) noexcept | bitwise-or-ed byte |\n| \u0026nbsp;            |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u0026amp;**( byte l, byte r ) noexcept | bitwise-xor-ed byte |\n| \u0026nbsp;            |  \u0026nbsp; | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte \u0026 **operator\u0026Hat;**( byte l, byte r ) noexcept | bitwise-and-ed byte|\n| Conversion        | non-std | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr byte **to_byte**( IntegerType v ) | byte with value v|\n| \u0026nbsp;            | \u003e=C++11 | template\u003c class IntegerType = *underlying-type* \u003e\u003cbr\u003econstexpr IntegerType **to_integer**( byte b ) | byte's value, note\u0026nbsp;2,\u0026nbsp;3|\n| \u0026nbsp;            | \u003c C++11 | template\u003c class IntegerType \u003e\u003cbr\u003econstexpr IntegerType **to_integer**( byte b ) | byte's value, note\u0026nbsp;3 |\n\n**Note 1**: the algorithms use an extra level of casting to prevent undefined behaviour, as mentioned by Thomas Köppe on mailing list isocpp-lib, subject \"std::byte operations are hard to use correctly\", on 16 March 2017.\n\n**Note 2**: default template parameter as suggested by Zhihao Yuan on mailing list isocpp-lib, subject \"std::byte to_integer\u003c\u003e\", on 10 March 2017.\n\n**Note 3**: use `to_integer()` to compute a byte's hash value.\n\n### Configuration macros\n\n#### Standard selection macro\n\\-D\u003cb\u003ebyte\\_CPLUSPLUS\u003c/b\u003e=199711L  \nDefine this macro to override the auto-detection of the supported C++ standard, if your compiler does not set the `__cpluplus` macro correctly.\n\n#### Select `std::byte` or `nonstd::byte`\nAt default, *byte lite* uses `std::byte` if it is available and lets you use it via namespace `nonstd`. You can however override this default and explicitly request to use `std::byte` or byte lite's `nonstd::byte` as `nonstd::byte` via the following macros.\n\n-D\u003cb\u003ebyte\\_CONFIG\\_SELECT\\_BYTE\u003c/b\u003e=byte_BYTE_DEFAULT  \nDefine this to `byte_BYTE_STD` to select `std::byte` as `nonstd::byte`. Define this to `byte_BYTE_NONSTD` to select `nonstd::byte` as `nonstd::byte`. Default is undefined, which has the same effect as defining to `byte_BYTE_DEFAULT`.\n\n\nReported to work with\n---------------------\nThe table below mentions the compiler versions *byte lite* is reported to work with.\n\nOS        | Compiler   | Versions |\n---------:|:-----------|:---------|\nWindows   | Clang/LLVM | ?        |\n\u0026nbsp;    | GCC        | 5.2.0    |\n\u0026nbsp;    | Visual C++\u003cbr\u003e(Visual Studio)| 6 (6), 8 (2005), 9 (2008), 10 (2010),\u003cbr\u003e11 (2012), 12 (2013), 14 (2015), 15 (2017) |\nGNU/Linux | Clang/LLVM | 3.5 - 6.0  |\n\u0026nbsp;    | GCC        | 4.8 - 8 |\nOS X      | Clang/LLVM | Xcode 6, Xcode 7, Xcode 8, Xcode 9 |\n\n\nBuilding the tests\n------------------\nTo build the tests you need:\n\n- [CMake](http://cmake.org), version 2.8.12 or later to be installed and in your PATH.\n- A [suitable compiler](#reported-to-work-with).\n\nThe [*lest* test framework](https://github.com/martinmoene/lest)  is included in the [test folder](test).\n\nThe following steps assume that the [*byte lite* source code](https://github.com/martinmoene/byte-lite) has been cloned into a directory named `c:\\byte-lite`.\n\n1. Create a directory for the build outputs for a particular architecture.\nHere we use c:\\byte-lite\\build-win-x86-vc10.\n\n        cd c:\\byte-lite\n        md build-win-x86-vc10\n        cd build-win-x86-vc10\n\n2. Configure CMake to use the compiler of your choice (run `cmake --help` for a list).\n\n        cmake -G \"Visual Studio 10 2010\" -DBYTE_LITE_OPT_BUILD_TESTS=ON ..\n\n3. Build the test suite in the Debug configuration (alternatively use Release).\n\n        cmake --build . --config Debug\n\n4. Run the test suite.\n\n        ctest -V -C Debug\n\nAll tests should pass, indicating your platform is supported and you are ready to use *byte lite*.\n\n\nOther implementations of byte\n----------------------------\n- Martin Moene. [gsl lite](https://github.com/martinmoene/gsl-lite). C++98 and later.\n- Microsoft. [Guideline Support Library (GSL)](https://github.com/microsoft/gsl). C++14 (supports MSVC 2013 and 2015).\n\n\nNotes and References\n--------------------\n[1] CppReference. [byte](http://en.cppreference.com/w/cpp/types/byte).\n\n[2] ISO/IEC WG21. [N4659, section 21.2.1, Header \u003ccstddef\u003e synopsis](http://wg21.link/n4659#page=492). March 2017.\n\n[3] Neil MacIntosh. [P0298: A byte type definition (Revision 3)](http://wg21.link/p0298). March 2017.\n\n\nAppendix\n--------\n\n### A.1 Compile-time information\n\nThe version of *byte lite* is available via tag `[.version]`. The following tags are available for information on the compiler and on the C++ standard library used: `[.compiler]`, `[.stdc++]`, `[.stdlanguage]` and `[.stdlibrary]`.\n\n### A.2 Byte lite test specification\n\n```\nbyte: Allows to construct from integral via static cast (C++17)\nbyte: Allows to construct from integral via byte() (C++17)\nbyte: Allows to construct from integral via to_byte()\nbyte: Allows to convert to integral via to_integer()\nbyte: Allows to convert to integral via to_integer(), using default type\nbyte: Allows comparison operations\nbyte: Allows bitwise or operation\nbyte: Allows bitwise and operation\nbyte: Allows bitwise x-or operation\nbyte: Allows bitwise or assignment\nbyte: Allows bitwise and assignment\nbyte: Allows bitwise x-or assignment\nbyte: Allows shift-left operation\nbyte: Allows shift-right operation\nbyte: Allows shift-left assignment\nbyte: Allows shift-right assignment\nbyte: Allows strict aliasing\nbyte: Provides constexpr non-assignment operations (C++11)\nbyte: Provides constexpr assignment operations (C++14)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinmoene%2Fbyte-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinmoene%2Fbyte-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinmoene%2Fbyte-lite/lists"}