Skip to content

optional-fun lite - Functional algorithms for optional (lite) for C++98, C++11 and later in a single-file header-only library

License

Notifications You must be signed in to change notification settings

martinmoene/optional-fun-lite

Repository files navigation

optional-fun lite: C++23's monadic operations of optional for C++98 and later

This library is still under (unintense) development.

Language License Build Status Build status Version download Try it online Try it on godbolt online

Contents

Example usage

#include "nonstd/optional-fun.hpp"
#include <iostream>

int main(int argc, char **)
{
}

Compile and run

$ g++ -std=c++11 -Wall -I../include/ -o main.exe main.cpp && main.exe

In a nutshell

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].

License

optional-fun lite is distributed under the Boost Software License.

Dependencies

optional-fun lite has no other dependencies than the C++ standard library.

Installation

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.

Synopsis

Documentation of class optional-fun

[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.

optional-fun lite implementation status

Kind Type or function Notes
     

Configuration

Other implementations

  • optional. C++11/14/17 std::optional with functional-style extensions and reference support. Simon Brand.

Notes and references

[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.

Appendix

A.1 Compile-time information

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].

A.2 Optional-fun lite test specification

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

About

optional-fun lite - Functional algorithms for optional (lite) for C++98, C++11 and later in a single-file header-only library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published