4.4.1
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
fcppt::either Namespace Reference

Contains fcppt::either::object and helper types/functions for it. More...

Classes

struct  is_object
 
struct  is_object< fcppt::either::object< Failure, Success > >
 
struct  no_error
 
class  object
 

Typedefs

template<typename Failure >
using error = fcppt::either::object< Failure, fcppt::either::no_error >
 An either without a success value.
 
template<fcppt::either::object_concept Either>
using failure_move_type = fcppt::move_if_rvalue_type< Either, fcppt::either::failure_reference_type< Either > >
 The moved failure type of an either.
 
template<fcppt::either::object_concept Either>
using failure_reference_type = decltype(std::declval< Either >().get_failure_unsafe())
 The failure reference type of an either.
 
template<fcppt::either::object_concept Either>
using failure_type = typename std::remove_cvref_t< Either >::failure
 The failure type of an either.
 
template<fcppt::either::object_concept Either>
using success_move_type = fcppt::move_if_rvalue_type< Either, fcppt::either::success_reference_type< Either > >
 The moved success type of an either.
 
template<fcppt::either::object_concept Either>
using success_reference_type = decltype(std::declval< Either >().get_success_unsafe())
 The success reference type of an either.
 
template<fcppt::either::object_concept Either>
using success_type = typename std::remove_cvref_t< Either >::success
 The success type of an either.
 

Functions

template<fcppt::either::object_concept Either1, fcppt::either::object_concept... Eithers, fcppt::concepts::invocable_move< fcppt::either::success_move_type< Either1 >, fcppt::either::success_move_type< Eithers >... > Function>
requires ( std::is_same_v<fcppt::either::failure_type<Either1>, fcppt::either::failure_type<Eithers>> &&...)
fcppt::either::object< fcppt::either::failure_type< Either1 >, std::invoke_result_t< Function, fcppt::either::success_move_type< Either1 >, fcppt::either::success_move_type< Eithers >... > > apply (Function const &_function, Either1 &&_either1, Eithers &&..._eithers)
 Applies a function to several eithers.
 
template<fcppt::either::object_concept Either, fcppt::concepts::invocable_move< fcppt::either::success_move_type< Either > > Function>
requires fcppt::either::is_object_v< std::invoke_result_t<Function, fcppt::either::success_move_type<Either>>> && std::is_same_v< fcppt::either::failure_type<Either>, fcppt::either::failure_type< std::invoke_result_t<Function, fcppt::either::success_move_type<Either>>>>
std::invoke_result_t< Function, fcppt::either::success_move_type< Either > > bind (Either &&_either, Function const &_function)
 Monadic bind on the success type of an either.
 
template<typename Failure , typename Success >
bool operator== (fcppt::either::object< Failure, Success > const &_a, fcppt::either::object< Failure, Success > const &_b)
 Compares two eithers for equality.
 
template<typename Failure , typename Success >
bool operator!= (fcppt::either::object< Failure, Success > const &_a, fcppt::either::object< Failure, Success > const &_b)
 Compares two eithers for inequality.
 
template<fcppt::concepts::invocable_move Failure, fcppt::concepts::invocable_move Success>
fcppt::either::object< std::invoke_result_t< Failure >, std::invoke_result_t< Success > > construct (bool const _value, Success const &_success, Failure const &_failure)
 Constructs an either by calling one of two functions.
 
template<fcppt::optional::object_concept Optional>
fcppt::either::error< fcppt::optional::value_type< Optional > > error_from_optional (Optional &&_optional)
 Converts an optional error to an either.
 
template<fcppt::either::object_concept Either>
fcppt::optional::object< fcppt::either::failure_type< Either > > failure_opt (Either &&_either)
 Returns the failure type as an optional.
 
template<typename Functions >
requires fcppt::concepts::invocable_move<fcppt::type_traits::value_type<Functions>> && fcppt::either::is_object_v<std::invoke_result_t<fcppt::type_traits::value_type<Functions>>>
fcppt::either::object< std::vector< fcppt::either::failure_type< std::invoke_result_t< fcppt::type_traits::value_type< Functions > > > >, fcppt::either::success_type< std::invoke_result_t< fcppt::type_traits::value_type< Functions > > > > first_success (Functions const &_functions)
 Call a container of functions, returning their first success or a container of failures.
 
template<fcppt::optional::object_concept Optional, fcppt::concepts::invocable_move FailureFunction>
fcppt::either::object< std::invoke_result_t< FailureFunction >, fcppt::optional::value_type< Optional > > from_optional (Optional &&_optional, FailureFunction const &_failure_function)
 Converts an optional to an either.
 
template<fcppt::either::object_concept Either>
requires fcppt::either::is_object_v<fcppt::either::success_type<Either>> && std::is_same_v< fcppt::either::failure_type<Either>, fcppt::either::failure_type<fcppt::either::success_type<Either>>>
fcppt::either::object< fcppt::either::failure_type< Either >, fcppt::either::success_type< fcppt::either::success_type< Either > > > join (Either &&_either)
 Removes one layer of eithers.
 
template<fcppt::concepts::invocable_move Next, fcppt::concepts::invocable< fcppt::either::success_type< std::invoke_result_t< Next > > > Loop>
requires fcppt::either::is_object_v<std::invoke_result_t<Next>>
fcppt::either::failure_type< std::invoke_result_t< Next > > loop (Next const &_next, Loop const &_loop)
 Loops a function returning an either.
 
template<fcppt::concepts::move_constructible Success, typename Failure >
fcppt::either::object< std::remove_cvref_t< Failure >, Success > make_failure (Failure &&_failure)
 Create an either with a failure.
 
template<fcppt::concepts::move_constructible Failure, typename Success >
fcppt::either::object< Failure, std::remove_cvref_t< Success > > make_success (Success &&_success)
 Create an either with a success.
 
template<fcppt::either::object_concept Either, fcppt::concepts::invocable_move< fcppt::either::success_move_type< Either > > Function>
fcppt::either::object< fcppt::either::failure_type< Either >, std::invoke_result_t< Function, fcppt::either::success_move_type< Either > > > map (Either &&_either, Function const &_function)
 Maps over the success type of an either.
 
template<fcppt::either::object_concept Either, fcppt::concepts::invocable_move< fcppt::either::failure_move_type< Either > > Function>
fcppt::either::object< std::invoke_result_t< Function, fcppt::either::failure_move_type< Either > >, fcppt::either::success_type< Either > > map_failure (Either &&_either, Function const &_function)
 Maps over the failure type of an either.
 
template<fcppt::either::object_concept Either, fcppt::concepts::invocable< fcppt::either::failure_move_type< Either > > FailureFunction, fcppt::concepts::invocable< fcppt::either::success_move_type< Either > > SuccessFunction>
requires std::is_same_v< std::invoke_result_t<SuccessFunction, fcppt::either::success_move_type<Either>>, std::invoke_result_t<FailureFunction, fcppt::either::failure_move_type<Either>>>
std::invoke_result_t< SuccessFunction, fcppt::either::success_move_type< Either > > match (Either &&_either, FailureFunction const &_failure_function, SuccessFunction const &_success_function)
 Matches on the two cases of an either.
 
bool operator== (fcppt::either::no_error const &, fcppt::either::no_error const &)
 Comparison of fcppt::either::no_error.
 
template<typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::either::no_error const &)
 Outputs fcppt::either::no_error.
 
template<typename Failure , typename Success , typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::either::object< Failure, Success > const &_either)
 Outputs an either to a basic_ostream.
 
template<fcppt::either::object_concept Result, typename Source >
Result sequence (Source &&_source)
 Sequences a container of eithers.
 
template<typename Sequence , fcppt::concepts::invocable_move< fcppt::container::to_value_type< std::remove_reference_t< Sequence > > > Function>
requires fcppt::either::is_object_v<std::invoke_result_t< Function, fcppt::container::to_value_type<std::remove_reference_t<Sequence>>>> && std::is_same_v< fcppt::either::success_type<std::invoke_result_t< Function, fcppt::container::to_value_type<std::remove_reference_t<Sequence>>>>, fcppt::either::no_error>
std::invoke_result_t< Function, fcppt::container::to_value_type< std::remove_reference_t< Sequence > > > sequence_error (Sequence &&_sequence, Function const &_function)
 Folds over a range, breaking out on the first error.
 
template<fcppt::either::object_concept Either>
fcppt::optional::object< fcppt::either::success_type< Either > > success_opt (Either &&_either)
 Returns the success type as an optional.
 
template<fcppt::either::object_concept Either, fcppt::concepts::invocable_move< fcppt::either::failure_move_type< Either > > MakeException>
fcppt::either::success_move_type< Either > to_exception (Either &&_either, MakeException const _make_exception)
 Returns the success value contained in an either or throws an exception.
 
template<fcppt::concepts::move_constructible Exception, fcppt::concepts::invocable_move Function, fcppt::concepts::invocable_move< Exception > ToException>
FCPPT_PP_PUSH_WARNING fcppt::either::object< std::invoke_result_t< ToException, Exception >, std::invoke_result_t< Function > > try_call (Function const &_function, ToException const &_to_exception)
 Catches exceptions of a function call and puts the result in an either.
 

Variables

template<typename T >
constexpr bool is_object_v = fcppt::either::is_object<T>::value
 Checks if a given type is an fcppt::either::object.
 

Detailed Description

Contains fcppt::either::object and helper types/functions for it.