{"id":15047265,"url":"https://github.com/martinmoene/status-value-lite","last_synced_at":"2025-04-10T00:51:01.359Z","repository":{"id":64005006,"uuid":"54899271","full_name":"martinmoene/status-value-lite","owner":"martinmoene","description":"status-value - A class for status and optional value for C++11 and later, C++98 variant provided in a single-file  header-only library","archived":false,"fork":false,"pushed_at":"2024-06-01T15:18:36.000Z","size":251,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T00:50:56.050Z","etag":null,"topics":["cpp11","cpp98","header-only","no-dependencies","optional","single-file","status","variant"],"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":"2016-03-28T14:45:52.000Z","updated_at":"2025-04-09T10:11:00.000Z","dependencies_parsed_at":"2024-02-04T16:35:29.755Z","dependency_job_id":"0eca54c3-b12e-4ada-aa04-cf775f37a18f","html_url":"https://github.com/martinmoene/status-value-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%2Fstatus-value-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fstatus-value-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fstatus-value-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinmoene%2Fstatus-value-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinmoene","download_url":"https://codeload.github.com/martinmoene/status-value-lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137998,"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":["cpp11","cpp98","header-only","no-dependencies","optional","single-file","status","variant"],"created_at":"2024-09-24T20:55:52.368Z","updated_at":"2025-04-10T00:51:01.314Z","avatar_url":"https://github.com/martinmoene.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# status_value: A class for status and optional value for C++11 and later\n\n[![Language](https://img.shields.io/badge/C%2B%2B-11-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization) [![Language](https://img.shields.io/badge/C%2B%2B-98-orange.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/status-value-lite/actions/workflows/ci.yml/badge.svg)](https://github.com/martinmoene/status-value-lite/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/i51ywyur2brx7r5q?svg=true)](https://ci.appveyor.com/project/martinmoene/status-value-lite) [![Version](https://badge.fury.io/gh/martinmoene%2Fstatus-value-lite.svg)](https://github.com/martinmoene/status-value-lite/releases) [![download](https://img.shields.io/badge/latest-download-blue.svg)](https://raw.githubusercontent.com/martinmoene/status-value-lite/master/include/nonstd/status_value.hpp) [![Conan](https://img.shields.io/badge/on-conan-blue.svg)](https://conan.io/center/status-value-lite) [![Vcpkg](https://img.shields.io/badge/on-vcpkg-blue.svg)](https://vcpkg.link/ports/status-value-lite) [![Try it on wandbox](https://img.shields.io/badge/on-wandbox-blue.svg)](https://wandbox.org/permlink/eRfjw7PDzh3ZOipS) [![Try it on godbolt online](https://img.shields.io/badge/on-godbolt-blue.svg)](https://godbolt.org/z/363wp-)\n\nstatus_value is a single-file header-only library for objects that represent a status and an optional value. It is intended for use with C++11 and later. There is a [separate variant](README_cpp98.md) for use with C++98 and later.\n\nThe library is based on the proposal for status_value [[1](#ref1)]. Please read [On proposed `status_value`](https://oliora.github.io/2022/01/20/On-proposed-status_value.html) by Andrey Upadyshev [[5](#ref5)] and consider if you truly want to use this library.\n\n**Contents**  \n\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- [Comparison with like types](#comparison)\n- [Reported to work with](#reported-to-work-with)\n- [Implementation notes](#implementation-notes)\n- [Notes and references](#notes-and-references)\n- [Appendix](#appendix)\n\n## Example usage\n\n```Cpp\n#include \"nonstd/status_value.hpp\"\n\n#include \u003ccstdlib\u003e\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n\nusing namespace nonstd;\nusing namespace std::literals;\n\nauto to_int( char const * const text ) -\u003e status_value\u003cstd::string, int\u003e \n{\n    char * pos = nullptr;\n    auto value = strtol( text, \u0026pos, 0 );\n\n    if ( pos != text ) return { \"Excellent\", value };\n    else               return { \"'\"s + text + \"' isn't a number\" };\n}\n\nint main( int argc, char * argv[] )\n{\n    auto text = argc \u003e 1 ? argv[1] : \"42\";\n\n    auto svi = to_int( text );\n\n    if ( svi ) std::cout \u003c\u003c svi.status() \u003c\u003c \": '\" \u003c\u003c text \u003c\u003c \"' is \" \u003c\u003c *svi \u003c\u003c \", \";\n    else       std::cout \u003c\u003c \"Error: \" \u003c\u003c svi.status();\n}\n```\n\n### Compile and run\n\n```\nprompt\u003e g++ -std=c++14 -Wall -I../include -o 01-basic.exe 01-basic.cpp \u0026\u0026 01-basic.exe 123 \u0026\u0026 01-basic.exe abc\nExcellent: '123' is 123, Error: 'abc' isn't a number\n```\n\n## In a nutshell\n\n**status_value** is a single-file header-only library to represent objects that contain a status and an optional value. The library is an implementation of the  proposal for [std:\u0026#58;status_value](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4233.html) [[1](#ref1),[2](#ref2)] for use with C++11 and later.\n\n**Features and properties of status_value** are ease of installation (single header), construction of a status, or a status and a value from a value that is convertible to the underlying type, move-construction from another status_value of the same type, testing for the presence of a value, operators and method value() for *checked* access to the value and access to the status.  \n\n**Not provided** are copy-construction of a status_value (by design), ... .\n\nFor more examples, see [[1](#ref1)].\n\n## License\n\n*status_value* is distributed under the [Boost Software License](https://github.com/martinmoene/span-lite/blob/master/LICENSE.txt).\n\n## Dependencies\n\n*status_value* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).\n\n## Installation\n\n\n*status_value* is a single-file header-only library. Put `status_value.hpp` directly into the project source tree or somewhere reachable from your project.\n\n## Synopsis\n\n**Contents**  \n\n- [Configuration macros](#configuration-macros)\n- [Interface of status_value](#interface-of-status_value)  \n\n### Configuration macros\n\n#### Tweak header\n\nIf the compiler supports [`__has_include()`](https://en.cppreference.com/w/cpp/preprocessor/include), *status_value lite* supports the [tweak header](https://vector-of-bool.github.io/2020/10/04/lib-configuration.html) mechanism. Provide your *tweak header* as `nonstd/status_value.tweak.hpp` in a folder in the include-search-path. In the tweak header, provide definitions as documented below, like `#define nsstsv_CPLUSPLUS 201103L`.\n\n#### Standard selection macro\n\\-D\u003cb\u003ensstsv\\_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#### Disable exceptions\n\\-D\u003cb\u003ensstsv\\_CONFIG\\_NO\\_EXCEPTIONS\u003c/b\u003e=0  \nDefine this to 1 if you want to compile without exceptions. If not defined, the header tries and detect if exceptions have been disabled (e.g. via -fno-exceptions). Disabling exceptions will force contract violation to call `std::abort()`. Default is 0.\n\n#### Enable compilation errors\n\\-D\u003cb\u003ensstsv\\_CONFIG\\_CONFIRMS\\_COMPILATION\\_ERRORS\u003c/b\u003e=0  \nDefine this macro to 1 to experience the by-design compile-time errors of the library in the test suite. Default is 0.\n\n### Interface of status_value\n\n| Kind           | Method                                                           | Result |\n|----------------|------------------------------------------------------------------|--------|\n| Type\u003cbr\u003e\u0026nbsp; | template\u0026lt;typename S\u003e\u003cbr\u003eclass **bad_status_value_access**;    | \u0026nbsp; |\n| Construction   | **bad_status_value_access**( S s )                               | move-construct from status |\n| \u0026nbsp;         | \u0026nbsp;                                                           | \u0026nbsp; |\n| Type\u003cbr\u003e\u0026nbsp; | template\u0026lt;typename S, typename V\u003e\u003cbr\u003eclass **status_value**;   | \u0026nbsp; |\n| Construction   | **status_value**() = delete                                      | disallow default construction |\n| \u0026nbsp;         | **status_value**( status_value \u0026\u0026 other )                        | move-construct from other |\n| \u0026nbsp;         | **status_value**( status_type const \u0026 s )                        | copy-construct from status |\n| \u0026nbsp;         | **status_value**( status_type const \u0026 s, value_type \u0026\u0026 v )       | copy-construct from status,\u003cbr\u003emove construct from value |\n| \u0026nbsp;         | **status_value**(  status_type const \u0026 s, value_type const \u0026 v ) | copy-construct from status and value |\n| Destruction    | **~status_value**()                                              | status, value destroyed if present|\n| Observers      | operator **bool**() const                                        | true if contains value |\n| \u0026nbsp;         | bool **has_value**() const                                       | true if contains value |\n| \u0026nbsp;         | status_type const \u0026 **status**() const                           | the status |\n| \u0026nbsp;         | value_type const \u0026 **value**() const                             | the value (const ref);\u003cbr\u003esee [note 1](#note1) |\n| \u0026nbsp;         | value_type \u0026 **value**()                                         | the value (non-const ref);\u003cbr\u003esee [note 1](#note1) |\n| \u0026nbsp;         | value_type const \u0026 **operator \\***() const                       | the value (const ref);\u003cbr\u003esee [note 1](#note1) |\n| \u0026nbsp;         | value_type \u0026 **operator \\***()                                   | the value (non-const ref);\u003cbr\u003esee [note 1](#note1) |\n| \u0026nbsp;         | value_type const \u0026 **operator -\u003e**() const                       | the element value (const ref);\u003cbr\u003esee [note 1](#note1) |\n| \u0026nbsp;         | value_type \u0026 **operator -\u003e**()                                   | the element value (non-const ref);\u003cbr\u003esee [note 1](#note1) |\n\n\u003ca id=\"note1\"\u003e\u003c/a\u003eNote 1: checked access: if no content, throws `bad_status_value_access` containing status value.\n\n\u003ca id=\"comparison\"\u003e\u003c/a\u003e\nComparison with like types\n--------------------------\n\n|Feature               |std::optional     |std::expected     |nonstd::status_value |\n|----------------------|------------------|------------------|---------------------|\n|More information      | see [[4](#ref4)] | see [[3](#ref3)] | this work           |\n|                      |                  |                  |                     |\n| C++98                | \u0026ndash;\u0026ensp;[note 2](#note2) | \u0026ndash; | \u0026ndash;\u0026ensp;[note 4](#note4)  |\n| C++11                | \u0026ndash;          | \u0026ndash;\u0026ensp;[note 3](#note3) | \u0026#10003; |\n| C++14                | \u0026ndash;          | \u0026ndash;          | \u0026#10003;            |\n| C++17                | \u0026#10003;         | \u0026ndash;          | \u0026#10003;            |\n|                      |                  |                  |                     |\n|DefaultConstructible  | \u0026#10003;         | \u0026#10003;         | \u0026#10003;            |\n|In-place construction | \u0026#10003;         | \u0026#10003;         | \u0026ndash;             |\n|Literal type          | \u0026#10003;         | \u0026#10003;         | \u0026ndash;             |\n|                      |                  |                  |                     |\n|Disengaged information| \u0026ndash;          | \u0026#10003;         | \u0026#10003;\u0026ensp;status|\n|Vary disengaged type  | \u0026ndash;          | \u0026#10003;         | \u0026#10003;\u0026ensp;status|\n|Engaged nonuse throws | \u0026ndash;          | \u0026ndash;          | \u0026ndash;             |\n|Disengaged use throws | \u0026#10003;\u0026ensp;value() | \u0026#10003;\u0026ensp;value() | \u0026#10003;\u0026ensp;all |\n|                      |                  |                  |                     |\n|Proxy (rel.ops)       | \u0026#10003;         | \u0026#10003;         | \u0026ndash;             |\n|References            | \u0026#10003;         | \u0026ndash;          | \u0026ndash;             |\n|Chained visitor(s)    | \u0026ndash;          | \u0026#10003;         | \u0026ndash;             |\n\n\u003ca id=\"note2\"\u003e\u003c/a\u003eNote 2: [optional lite](https://github.com/martinmoene/optional-lite) - Optional (nullable) objects for C++98 and later.  \n\u003ca id=\"note3\"\u003e\u003c/a\u003eNote 3: [expected lite](https://github.com/martinmoene/expected-lite) - Expected objects for C++11 and later.  \n\u003ca id=\"note4\"\u003e\u003c/a\u003eNote 4: This project provides a [variant of status_value](README_cpp98.md) for use with C++98 and later.\n\n## Reported to work with\n\n*status_value* is reported to work with the following compilers: \n\n- Visual VC14 (VS2015)\n- GNUC 5.2.0 with -std=c++11, -std=c++14, -std=c++1y \n- clang 3.6, 3.7 with -std=c++11, -std=c++14 (on Travis)\n\n## Implementation notes\n\n## Notes and references\n\n\u003ca id=\"ref1\"\u003e\u003c/a\u003e[1] Lawrence Crowl and Chris Mysen. [p0262 - A Class for Status and Optional Value (latest)](http://wg21.link/p0262), 14 February 2016. [N4233](http://wg21.link/n4233), 10 October 2014.\n\n\u003ca id=\"ref2\"\u003e\u003c/a\u003e[2] Lawrence Crowl. [p0157 - Handling Disappointment in C++ (latest)](http://wg21.link/p0157), 7 July 2015.\n\n\u003ca id=\"ref3\"\u003e\u003c/a\u003e[3] Vicente J. Botet Escriba. [p0323 - A proposal to add a utility class to represent expected object (latest)](http://wg21.link/p0323) (PDF). ([r6](http://wg21.link/p0323r6), [r5](http://wg21.link/p0323r5), [r4](http://wg21.link/p0323r4), [r3](http://wg21.link/p0323r3), [r2](http://wg21.link/p0323r2), [r1](http://wg21.link/n4109), [r0](http://wg21.link/n4015), [draft](https://github.com/viboes/std-make/blob/master/doc/proposal/expected/DXXXXR0_expected.pdf)).\n\n\u003ca id=\"ref4\"\u003e\u003c/a\u003e[4] Fernando Cacciola and Andrzej Krzemieński. [N3793 - A proposal to add a utility class to represent optional objects (Revision 5)](http://wg21.link/n3793). 03 October 2013. [N3672 r4](http://wg21.link/n3672), [N3527 r3](http://wg21.link/n3527), [N3406 r2](http://wg21.link/n3406), [N1878 r1](http://wg21.link/n1878), [N3966 - Fixes for optional objects](http://wg21.link/n3966).\n\n\u003ca id=\"ref5\"\u003e\u003c/a\u003e[5] Andrey Upadyshev. [On proposed `status_value`](https://oliora.github.io/2022/01/20/On-proposed-status_value.html). 20 January 2022.\n\n## Appendix\n\n### A.1 Compile-time information\n\nThe version of *status-value 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 Status_value test specification\n\n\u003cdetails\u003e\n\u003csummary\u003eclick to expand\u003c/summary\u003e\n\u003cp\u003e\n\n```\nstatus_value\u003c\u003e: Disallows default construction\nstatus_value\u003c\u003e: Allows construction from only status\nstatus_value\u003c\u003e: Allows construction from status and non-default-constructible value\nstatus_value\u003c\u003e: Allows construction from copied status and moved value\nstatus_value\u003c\u003e: Allows construction from copied status and copied value\nstatus_value\u003c\u003e: Disallows copy-construction from other status_value of the same type\nstatus_value\u003c\u003e: Allows move-construction from other status_value of the same type\nstatus_value\u003c\u003e: Allows to observe its status\nstatus_value\u003c\u003e: Allows to observe the presence of a value (has_value())\nstatus_value\u003c\u003e: Allows to observe the presence of a value (operator bool)\nstatus_value\u003c\u003e: Allows to observe its value (value())\nstatus_value\u003c\u003e: Allows to observe its value (operator*)\nstatus_value\u003c\u003e: Allows to observe its value (operator-\u003e)\nstatus_value\u003c\u003e: Throws when observing non-engaged (value())\nstatus_value\u003c\u003e: Throws when observing non-engaged (operator*())\nstatus_value\u003c\u003e: Throws when observing non-engaged (operator-\u003e())\ntweak header: reads tweak header if supported [tweak]\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinmoene%2Fstatus-value-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinmoene%2Fstatus-value-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinmoene%2Fstatus-value-lite/lists"}