MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
result.hpp File Reference
#include "../core.hpp"
#include "../traits.hpp"
#include "optional.hpp"
#include <memory>
#include <ostream>
#include <variant>
Include dependency graph for result.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mtcore::Error< Underlying >
 A struct representing an error Auto convertible to a Result of any type. More...
 
struct  mtcore::Result< void, ErrType >
 Represents a Result that may have an error (error code) or a success (without a value) More...
 
struct  mtcore::Result< T, ErrType >
 Represents a Result that may have an error (error code) or a success value A type of "void" means there is no Result value, but there may be a failure. More...
 
struct  mtcore::Success< void >
 Represents a success value. More...
 
struct  mtcore::Success< T >
 Represents a success result (auto castable to Result) More...
 

Namespaces

namespace  mtcore
 Core library for C++ with Zig-related functionality.
 
namespace  mtcore::results
 Additional algorithms and pipeline functionality that can be performed on groups of results.
 

Macros

#define MTCORE_RESULT_H
 

Functions

template<typename T>
Success< T > mtcore::success (const T &v)
 Creates a successful Result.
 
Success< void > mtcore::success ()
 Creates a successful void Result object.
 
template<typename Underlying>
Error< Underlying > mtcore::error (Underlying err)
 Creates an error.
 
template<typename Success, typename Acc, typename F, Iterable I, typename Err = typename decltype(std::declval<F>()( std::declval<std::remove_const_t<typename decltype(std::declval<I>().iter())::IterElem>>()))::Err>
Result< Success, Err > mtcore::results::accumulate (Success initial, const Acc &acc, const F &func, const I &iterable)
 Chains together the execution of an errorable function on a list of arguments If an error is encountered, execution will stop and immediately return No Result value is returned Useful for performing side effects.
 
template<typename F, Iterable I, typename Err = typename decltype(std::declval<F>()( std::declval<std::remove_const_t<typename decltype(std::declval<I>().iter())::IterElem>>()))::Err>
Result< void, Err > mtcore::results::foreach (const F &func, const I &iterable)
 Chains together the execution of an errorable function on a list of arguments If an error is encountered, execution will stop and immediately return No Result value is returned Useful for performing side effects.
 
template<typename F, typename... Args, typename Err = typename decltype(std::declval<F>()(std::declval<typename impl::FirstVariadic<Args...>::Type>()))::Err>
Result< void, Err > mtcore::results::chain (const F &func, const Args &...args)
 Chains together the execution of an errorable function on a list of arguments If an error is encountered, execution will stop and immediately return No Result value is returned Useful for performing side effects.
 
template<typename Success, typename Acc, typename F, typename... Args, typename Err = typename decltype(std::declval<F>()(std::declval<typename impl::FirstVariadic<Args...>::Type>()))::Err>
Result< Success, Err > mtcore::results::reduce (Success initVal, const Acc &acc, const F &func, const Args &...args)
 Reduces arguments with errorable function If an error is encountered, execution will stop and immediately return The accumulated Result will be what's returned on success Useful for reduction/mapping.
 
template<typename F, typename... Args, typename Out = typename decltype(std::declval<F>()(std::declval<typename impl::FirstVariadic<Args...>::Type>()))::Value, typename Err = typename decltype(std::declval<F>()(std::declval<typename impl::FirstVariadic<Args...>::Type>()))::Err>
auto mtcore::results::map (const F &func, const Args &...args)
 Maps values with function that may error.
 

Macro Definition Documentation

◆ MTCORE_RESULT_H

#define MTCORE_RESULT_H

Definition at line 22 of file result.hpp.