C++14 header only result monad implementation

constexpr Either <S, E>

C++14 header only result monad implementation.

Features

  • constexpr support
  • 0 dependencies
  • single header

Status

  • in development
  • TODOs:
    • expand test coverage
    • stricter compile time constraints
    • support for function return types
    • support std::hash for either
    • write small docs

Example

#include <et/either.hpp>
#include <iostream>
#include <string>
#include <vector>

auto Example(std::int32_t val) -> et::Either<std::int32_t, std::string> {
  using namespace std::string_literals;
  if (val > 0) {
    return et::Success(2 * val);
  } else {
    return et::Error("[example::Example] error: val must be > 0"s);
  }
}

int main(void) {
  std::cout << Example(2) << std::endl;
  std::cout << Example(-1) << std::endl;

  std::vector<et::Either<std::int32_t, char>> vec = {
      et::Success(312), et::Error('v'), et::Success(420)};

  return EXIT_SUCCESS;
}
Owner
simplicity is efficiency
null
Similar Resources

Step is a C++17, header-only library of STL-like algorithms and data structures

Step is a C++17, header-only library of STL-like algorithms and data structures

Step is a C++17, header-only library of STL-like algorithms and data structures. Installation git clone --depth 1 https://github.com/storm-ptr/step.gi

Sep 1, 2022

R :package: and header-only C++ library for geospatial space-division based compression and encoding

R :package: and header-only C++ library for geospatial space-division based compression and encoding

spress spress provides utilities for encoding and compressing geospatial objects, such as sf objects. Installation This package requires C++11 for com

Dec 9, 2021

R :package: and header-only C++ library for geospatial space-division based compression and encoding

R :package: and header-only C++ library for geospatial space-division based compression and encoding

spress spress provides utilities for encoding and compressing geospatial objects, such as sf objects. Installation This package requires C++11 for com

Dec 9, 2021

Play GTA San Andreas Multiplayer with mouse only and no keyboard

Play GTA SAMP with your mouse and no keyboard! For some reason some people think it's a troll or an inside joke, IT IS NOT! This is a legit mod for th

Aug 31, 2022

Like neofetch, but much faster because written in c. Only Linux.

Like neofetch, but much faster because written in c. Only Linux.

fastfetch fastfetch is a neofetch like tool for fetching system information and displaying them in a pretty way. It is written in c to achieve much be

Dec 3, 2022

C header library for typed lists (using macros and "template" C).

vector.h C header library for typed lists (using macros and "template" C). Essentially, this is a resizable array of elements of your choosing that is

Nov 29, 2022

Miniz in a single C header.

MiniMiniZ This the amalgamated miniz library in a single header. Usage Copy miniminiz.h into your C or C++ project, include it anywhere you want to us

Jul 20, 2022

A reverse engineering tool to interactively reconstruct structures and generate header files

A reverse engineering tool to interactively reconstruct structures and generate header files

ReGenny ReGenny is a reverse engineering tool to interactively reconstruct structures and generate usable C++ header files. Header file generation is

Nov 27, 2022

C header to execute user-space functions in ring 0

r0e - Execute User Code in Ring0 This small header allows executing functions in your application in ring 0, i.e., with kernel privileges. Use cases i

Nov 11, 2022
Related tags
BladeBit - Fast Chia (XCH) RAM-only k32-only Plotter

BladeBit Chia Plotter A fast RAM-only, k32-only, Chia plotter. Requirements 416 GiB of RAM are required to run it, plus a few more megabytes for stack

Nov 28, 2022
Easy to use, header only, macro generated, generic and type-safe Data Structures in C
Easy to use, header only, macro generated, generic and type-safe Data Structures in C

C Macro Collections Easy to use, header only, macro generated, generic and type-safe Data Structures in C. Table of Contents Installation Contributing

Nov 27, 2022
nanoplan is a header-only C++11 library for search-based robot planning.
nanoplan is a header-only C++11 library for search-based robot planning.

nanoplan is a header-only C++11 library for search-based robot planning. The primary design goals are correctness, ease-of-use, and efficiency (in tha

May 17, 2022
Simple Useful Libraries: C++17/20 header-only dynamic bitset

dynamic_bitset Simple Useful Libraries: C++17/20 header-only dynamic bitset Requirements To use this dynamic bitset, you will need a C++17 (or later)

Nov 16, 2022
a header-only, constexpr alternative to gperf for C++14 users

Frozen Header-only library that provides 0 cost initialization for immutable containers, fixed-size containers, and various algorithms. Frozen provide

Nov 25, 2022
A family of header-only, very fast and memory-friendly hashmap and btree containers.
A family of header-only, very fast and memory-friendly hashmap and btree containers.

The Parallel Hashmap Overview This repository aims to provide a set of excellent hash map implementations, as well as a btree alternative to std::map

Nov 25, 2022
ring-span lite - A C++yy-like ring_span type for C++98, C++11 and later in a single-file header-only library

ring-span lite: A circular buffer view for C++98 and later Contents Example usage In a nutshell Dependencies Installation Synopsis Reported to work wi

Nov 26, 2022
Header-only compile time key-value map written in C++20.

C++ Static Map Header-only compile time key-value map written in C++20. Getting Started Simply add the files in your source and #include "@dir/Static_

Oct 19, 2021
Multi-Purpose Header-Only C Data Structures

USAGE These header files are meant to be a simple means of using datastructures in a C project. They are universally useable with any other C datatype

Jul 15, 2022
A simple single header 64 and 32 bit hash function using only add, sub, ror, and xor.
A simple single header 64 and 32 bit hash function using only add, sub, ror, and xor.

K-HASH A simple single header 64 bit hash function using only add, sub, ror, and xor. This a just general-purpose hash function for like making hash m

Jul 31, 2022