{"id":15047270,"url":"https://github.com/martinmoene/boolean-lite","last_synced_at":"2025-04-10T01:23:58.085Z","repository":{"id":53745052,"uuid":"308913333","full_name":"martinmoene/boolean-lite","owner":"martinmoene","description":"boolean lite: A strong boolean type for C++98 and later","archived":false,"fork":false,"pushed_at":"2024-01-14T15:24:30.000Z","size":48,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T03:05:17.054Z","etag":null,"topics":["boolean","cpp11","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":null,"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":"2020-10-31T15:35:18.000Z","updated_at":"2023-06-01T20:25:44.000Z","dependencies_parsed_at":"2024-10-12T16:40:58.230Z","dependency_job_id":null,"html_url":"https://github.com/martinmoene/boolean-lite","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fboolean-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fboolean-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fboolean-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fboolean-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinmoene","download_url":"https://codeload.github.com/martinmoene/boolean-lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248138789,"owners_count":21053953,"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":["boolean","cpp11","cpp17","cpp98","header-only","no-dependencies","single-file"],"created_at":"2024-09-24T20:55:56.554Z","updated_at":"2025-04-10T01:23:58.066Z","avatar_url":"https://github.com/martinmoene.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# boolean lite: A strong boolean type for C++98 and later\n\n[![Language](https://img.shields.io/badge/C%2B%2B-98/11/14/17/20-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/boolean-lite/actions/workflows/ci.yml/badge.svg)](https://github.com/martinmoene/boolean-lite/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/1ha3wnxtam547m8p?svg=true)](https://ci.appveyor.com/project/martinmoene/boolean-lite) [![Version](https://badge.fury.io/gh/martinmoene%2Fboolean-lite.svg)](https://github.com/martinmoene/boolean-lite/releases) [![download](https://img.shields.io/badge/latest-download-blue.svg)](https://github.com/martinmoene/boolean-lite/blob/master/include/nonstd/boolean.hpp) [![Conan](https://img.shields.io/badge/on-conan-blue.svg)](https://conan.io/center/boolean-lite) [![Try it on wandbox](https://img.shields.io/badge/on-wandbox-blue.svg)](https://wandbox.org/permlink/TMURDai5p2CSWn9a) [![Try it on godbolt online](https://img.shields.io/badge/on-godbolt-blue.svg)](https://godbolt.org/z/E1onYM)\n\n**Contents**  \n\n- [Example usage](#example-usage)\n- [In a nutshell](#in-a-nutshell)\n- [License](#license)\n- [Dependencies](#dependencies)\n- [Installation and use](#installation-and-use)\n- [Synopsis](#synopsis)\n- [Notes and references](#notes-and-references)\n- [Appendix](#appendix)\n\n\u003c!--\n- [Reported to work with](#reported-to-work-with)\n- [Building the tests](#building-the-tests)\n- [Other implementations of boolean](#other-implementations-of-boolean)\n--\u003e\n\n## Example usage\n\n```cpp\n#include \"nonstd/boolean.hpp\"\n#include \u003ciostream\u003e\n\nusing nonstd::boolean_;\n\nvoid eat_cookies( int count, boolean_ leave_crumbs )\n{\n    std::cout \u003c\u003c \"Eat \" \u003c\u003c count \u003c\u003c \" cookies and leave \" \u003c\u003c (leave_crumbs ? \"\" : \"no \") \u003c\u003c \"crumbs\\n\";\n}\n\nvoid santa( int num_cookies )\n{\n    const boolean_ leave_crumbs = num_cookies \u003e 4;\n\n//  eat_cookies( leave_crumbs, num_cookies );  // Does not compile: wrong argument order\n    eat_cookies( num_cookies, leave_crumbs );  // Ok\n}\n\nint main()\n{\n    santa( 3 );\n    santa( 5 );\n}\n```\n\n### Compile and run\n\n```bash\nprompt \u003eg++ -std=c++11 -Wall -I../include -o 01-basic.exe 01-basic.cpp \u0026\u0026 01-basic.exe\nEat 3 cookies and leave no crumbs\nEat 5 cookies and leave crumbs\n```\n\n## In a nutshell\n\n**boolean lite** is a single-file header-only library to provide a strong boolean type.\n\n*boolean lite* is inspired on the article [Fun with Concepts: Do You Even Lift, Bool?](https://vector-of-bool.github.io/2020/10/26/strong-bool.html) by Colby Pike (vector-of-bool), Oct 26, 2020.\n\n**Features and properties of boolean lite** are ease of installation (single header), freedom of dependencies other than the standard library.\n\n## License\n\n*boolean lite* is distributed under the [Boost Software License](https://github.com/martinmoene/boolean-lite/blob/master/LICENSE.txt).\n\n## Dependencies\n\n*boolean lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).\n\n## Installation and use\n\n*boolean lite* is a single-file header-only library. Put `boolean.hpp` in the [include](include) folder directly into the project source tree or somewhere reachable from your project.\n\n## Synopsis\n\n**Contents**  \n[Documentation of `nonstd::boolean`](#documentation-of-nonstdboolean)  \n[Configuration](#configuration)  \n\n### Documentation of `nonstd::boolean`\n\nThe behaviour of boolean differs under C++98 and C++11 and later. Specifically the C++11 version allows the following that is not supported by the C++98 version of `boolean_`.\n\n- copy initialization like `boolean_ b = true;`\n- comparison to `bool`, like `boolean_ f( false ); boolean_ result = f == true;`\n\nNote: The name `boolean_` is used for the type to prevent clashing with type `boolean` from the Windows SDK (rpcndr.h(193)).\n\n| Kind                    | std   | Function or method |\n|-------------------------|-------|--------------------|\n| **Construction**        |C++11  | template\u0026lt;typename T *[bool]*\u003e constexpr **boolean\\_(T v)** noexcept; |\n| \u0026nbsp;                  |\u0026#8942;| template\u0026lt;typename T *[!bool]*\u003e explicit constexpr **boolean\\_(T v)** noexcept; |\n| **Conversion**          |\u0026#8942;| template\u0026lt;typename T *[bool]*\u003e \\[[nodiscard]] constexpr **operator T()** const noexcept; |\n| \u0026nbsp;                  |\u0026#8942;| template\u0026lt;typename T *[!bool]*\u003e \\[[nodiscard]] explicit constexpr **operator T()** const noexcept; |\n| **Negation**            |\u0026#8942;| \\[[nodiscard]] friend explicit constexpr **operator!()** const noexcept; |\n| **Equality**            |\u0026#8942;| \\[[nodiscard]] friend explicit constexpr **operator==(boolean\\_ a, boolean\\_ b)** noexcept; |\n| \u0026nbsp;                  |\u0026#8942;| \\[[nodiscard]] friend explicit constexpr **operator!=(boolean\\_ a, boolean\\_ b)** noexcept; |\n| **Ordering**            |\u0026#8942;| \\[[nodiscard]] friend explicit constexpr **operator\u003c(boolean\\_ a, boolean\\_ b)** noexcept; |\n| \u0026nbsp;                  |\u0026#8942;| \\[[nodiscard]] friend explicit constexpr **operator\u003e(boolean\\_ a, boolean\\_ b)** noexcept; |\n| \u0026nbsp;                  |\u0026#8942;| \\[[nodiscard]] friend explicit constexpr **operator\u003c=(boolean\\_ a, boolean\\_ b)** noexcept; |\n| \u0026nbsp;                  |C++11  | \\[[nodiscard]] friend explicit constexpr **operator\u003e=(boolean\\_ a, boolean\\_ b)** noexcept; |\n| \u0026nbsp;                  |\u0026nbsp; |\u0026nbsp;|\n| **Construction**\u003cbr\u003e\u0026nbsp;|C++98\u003cbr\u003e\u0026nbsp;  | explicit **boolean\\_(bool v)**;\u003cbr\u003eNote: no copy initialization: `boolean_ b = true;` |\n| **Conversion**\u003cbr\u003e\u0026nbsp;  |\u0026#8942;\u003cbr\u003e\u0026nbsp;| operator **bool_type()** const;\u003cbr\u003eNote: bool_type allows for safe conversions |\n| **Negation**            |\u0026#8942;| boolean_ **operator!()** const; |\n| **Equality**            |\u0026#8942;| friend boolean\\_ **operator==(boolean\\_ a, boolean\\_ b)**; |\n| \u0026nbsp;                  |\u0026#8942;| friend boolean\\_ **operator!=(boolean\\_ a, boolean\\_ b)**; |\n| **Ordering**            |\u0026#8942;| friend boolean\\_ **operator\u003c(boolean\\_ a, boolean\\_ b)**; |\n| \u0026nbsp;                  |\u0026#8942;| friend boolean\\_ **operator\u003e(boolean\\_ a, boolean\\_ b)**; |\n| \u0026nbsp;                  |\u0026#8942;| friend boolean\\_ **operator\u003c=(boolean\\_ a, boolean\\_ b)**; |\n| \u0026nbsp;                  |C++98  | friend boolean\\_ **operator\u003e=(boolean\\_ a, boolean\\_ b)**; |\n\n### Configuration\n\n#### Tweak header\n\nIf the compiler supports [`__has_include()`](https://en.cppreference.com/w/cpp/preprocessor/include), *boolean lite* supports the [tweak header](https://vector-of-bool.github.io/2020/10/04/lib-configuration.html) mechanism. Provide your *tweak header* as `nonstd/boolean.tweak.hpp` in a folder in the include-search-path. In the tweak header, provide definitions as documented below, like `#define boolean_CPLUSPLUS 201103L`.\n\n#### Standard selection macro\n\n\\-D\u003cb\u003eboolean\\_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 `__cplusplus` macro correctly.\n\n## Notes and references\n\n- [Fun with Concepts: Do You Even Lift, Bool?](https://vector-of-bool.github.io/2020/10/26/strong-bool.html) by Colby Pike ([vector-of-bool](https://github.com/vector-of-bool)), Oct 26, 2020.\n- [A New Approach to Build-Time Library Configuration](https://vector-of-bool.github.io/2020/10/04/lib-configuration.html) by Colby Pike ([vector-of-bool](https://github.com/vector-of-bool)), Oct 4, 2020.\n\n## Appendix\n\n### A.1 Compile-time information\n\nThe version of *boolean 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 Span lite test specification\n\n```Text\nboolean: Allows to direct initialize from bool\nboolean: Allows to copy initialize from bool (C++11)\nboolean: Allows to direct initialize from type convertible to bool\nboolean: Allows to compare equal\nboolean: Allows to compare unequal\nboolean: Allows to compare less than\nboolean: Allows to compare less than or equal\nboolean: Allows to compare greater than\nboolean: Allows to compare greater than or equal\nboolean: Allows to compare equal with bool (C++11)\nboolean: Allows to compare unequal with bool (C++11)\nboolean: Allows to compare less than with bool (C++11)\nboolean: Allows to compare less than or equal with bool (C++11)\nboolean: Allows to compare greater than with bool (C++11)\nboolean: Allows to compare greater than or equal with bool (C++11)\nboolean: Supports no discard (C++17, -DBOOLEAN_TEST_NODISCARD=1)\ntweak header: Reads tweak header if supported [tweak]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinmoene%2Fboolean-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinmoene%2Fboolean-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinmoene%2Fboolean-lite/lists"}