This library is still under (unintense) development.
Contents
- Example usage
- In a nutshell
- License
- Dependencies
- Installation
- Synopsis
- Other implementations
- Notes and references
- Appendix
#include "nonstd/optional-fun.hpp"
#include <iostream>
int main(int argc, char **)
{
}
$ g++ -std=c++11 -Wall -I../include/ -o main.exe main.cpp && main.exe
optional-fun lite is a single-file header-only library to provide C++23 monadic operations to C++17's class optional for use with C++98 and later.
Currently this library does not (yet) support ... .
Features and properties of optional-fun lite are ease of installation (single header), freedom of dependencies other than the standard library.
Limitations of optional-fun lite are ... [to be summed up].
optional-fun lite is distributed under the Boost Software License.
optional-fun lite has no other dependencies than the C++ standard library.
optional-fun lite is a single-file header-only library. Put optional-fun.hpp
in the include folder directly into the project source tree or somewhere reachable from your project.
[Envisioned] Depending on the compiler and C++ standard used, optional-fun lite behaves less or more like the standard's version. To get an idea of the capabilities of optional-fun lite with your configuration, look at the output of the tests, issuing optional-fun-main.t --pass @
.
For the standard's documentation, see section Member functions, Monadic operations of class optional
, which is part of the C++ Utility library.
Kind | Type or function | Notes |
---|---|---|
- optional. C++11/14/17 std::optional with functional-style extensions and reference support. Simon Brand.
[1] CppReference. Optional.
[2] ISO/IEC WG21. Draft 2022-11-11, section 22.5 Optional objects. 2022.
[3] ISO/IEC WG21. Draft 2022-11-11, section 22.5.3.7 Optional objects, Monadic operations. 2022.
[4] Simon Brand. p0798 - Monadic operations for std::optional. 2019.
The version of optional-fun 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]
.
click to expand
optional-fun.t.cpp(28): passed: optional map(f): non-void[functional]: 2*v == (optional<int>(v) | map( double_int )).value() for 42 == 42
optional-fun.t.cpp(41): passed: optional map(f): void[functional]: monostate() == (optional<int>(v) | map( voider_int )).value() for [monostate] == [monostate]
optional-fun.t.cpp(50): passed: optional map_or(f): [functional]: 14 == (optional<int>( 7 ) | map_or( double_int, 42 )) for 14 == 14
optional-fun.t.cpp(51): passed: optional map_or(f): [functional]: 42 == (optional<int>( ) | map_or( double_int, 42 )) for 42 == 42
optional-fun.t.cpp(58): passed: optional map_or_else(f): [functional]: 14 == (optional<int>( 7 ) | map_or_else( double_int, seven )) for 14 == 14
optional-fun.t.cpp(59): passed: optional map_or_else(f): [functional]: 7 == (optional<int>( ) | map_or_else( double_int, seven )) for 7 == 7
optional-fun.t.cpp(69): passed: optional and_then(f): success[functional]: 2*v == (optional<int>(v) | then( double_opt )).value() for 42 == 42
optional-fun.t.cpp(70): passed: optional and_then(f): success[functional]: 2*v == (optional<int>(v) | and_then( double_opt )).value() for 42 == 42
optional-fun.t.cpp(78): passed: optional and_then(f): fail[functional]: ! ( (optional<int>(7) | and_then( double_opt ) | and_then( fail_opt ) | and_then( double_opt )).has_value() ) for ! ( false )
optional-fun.t.cpp(86): passed: optional or_else(f): non-void[functional]: -1 == (optional<int>(-1) | or_else( fun_or_else_nonvoid )).value() for -1 == -1
optional-fun.t.cpp(87): passed: optional or_else(f): non-void[functional]: fun_or_else_nonvoid() == (optional<int>( ) | or_else( fun_or_else_nonvoid )).value() for 7 == 7
optional-fun.t.cpp(92): passed: optional or_else(f): void[functional]: -1 == (optional<int>(-1) | or_else( fun_or_else_void )).value() for -1 == -1
optional-fun.t.cpp(93): passed: optional or_else(f): void[functional]: ! ( (optional<int>( ) | or_else( fun_or_else_void )).has_value() ) for ! ( false )
optional-fun.t.cpp(98): passed: optional and_(u): [functional]: 42 == (optional<int>(7) | and_( 42 )).value() for 42 == 42
optional-fun.t.cpp(99): passed: optional and_(u): [functional]: ! ( (optional<int>( ) | and_( 42 )).has_value() ) for ! ( false )
optional-fun.t.cpp(104): passed: optional or_(rhs): [functional]: 7 == (optional<int>(7) | or_( 42 )) for 7 == 7
optional-fun.t.cpp(105): passed: optional or_(rhs): [functional]: 42 == (optional<int>( ) | or_( 42 )) for 42 == 42