3.0.0
Freundlich's C++ toolkit
Classes | Typedefs | Functions
fcppt::either Namespace Reference

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

Classes

struct  is_object
 
class  object
 
struct  object< Failure, Success >>
 

Typedefs

template<typename Failure >
using error = fcppt::either::object< Failure, fcppt::either::no_error >
 An either without a success value. More...
 
template<typename Either >
using failure_type = typename fcppt::either::detail::failure_type< Either >::type
 The failure type of an either. More...
 
typedef fcppt::unit no_error
 The type that represents no error in an fcppt::either::error. More...
 
template<typename Either >
using success_type = typename fcppt::either::detail::success_type< Either >::type
 The success type of an either. More...
 

Functions

template<typename Function , typename Either1 , typename... Eithers>
auto apply (Function const &_function, Either1 &&_either1, Eithers &&..._eithers) -> fcppt::either::object< fcppt::either::failure_type< fcppt::type_traits::remove_cv_ref_t< Either1 > >, decltype(_function(fcppt::move_if_rvalue< Either1 >(_either1.get_success_unsafe()), fcppt::move_if_rvalue< Eithers >(_eithers.get_success_unsafe())...)) >
 Applies a function to several eithers. More...
 
template<typename Either , typename Function >
auto bind (Either &&_either, Function const &_function) -> decltype(_function(fcppt::move_if_rvalue< Either >(_either.get_success_unsafe())))
 Monadic bind on the success type of an either. More...
 
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. More...
 
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. More...
 
template<typename Optional >
auto error_from_optional (Optional &&_optional) -> fcppt::either::error< fcppt::optional::value_type< fcppt::type_traits::remove_cv_ref_t< Optional > > >
 Converts an optional error to an either. More...
 
template<typename Either >
fcppt::optional::object< fcppt::either::failure_type< fcppt::type_traits::remove_cv_ref_t< Either > >> failure_opt (Either &&_either)
 Returns the failure type as an optional. More...
 
template<typename Functions >
fcppt::either::object< std::vector< fcppt::either::failure_type< std::result_of_t< fcppt::type_traits::value_type< Functions >) > > >, fcppt::either::success_type< std::result_of_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. More...
 
template<typename Sequence , typename Function >
auto fold_error (Sequence &&_sequence, Function const &_function) -> decltype(_function(std::declval< fcppt::container::to_value_type< std::remove_reference_t< Sequence > > >()))
 Folds over a range, breaking out on the first error. More...
 
template<typename Optional , typename FailureFunction >
auto from_optional (Optional &&_optional, FailureFunction const &_failure_function) -> fcppt::either::object< decltype(_failure_function()), fcppt::optional::value_type< fcppt::type_traits::remove_cv_ref_t< Optional > > >
 Converts an optional to an either. More...
 
template<typename Either >
fcppt::either::object< fcppt::either::failure_type< fcppt::type_traits::remove_cv_ref_t< Either > >, fcppt::either::success_type< fcppt::either::success_type< fcppt::type_traits::remove_cv_ref_t< Either > > >> join (Either &&_either)
 Joins an either. More...
 
template<typename Success , typename Failure >
fcppt::either::object< fcppt::type_traits::remove_cv_ref_t< Failure >, Success > make_failure (Failure &&_failure)
 Create an either with a failure. More...
 
template<typename Failure , typename Success >
fcppt::either::object< Failure, fcppt::type_traits::remove_cv_ref_t< Success >> make_success (Success &&_success)
 Create an either with a success. More...
 
template<typename Either , typename Function >
auto map (Either &&_either, Function const &_function) -> fcppt::either::object< fcppt::either::failure_type< fcppt::type_traits::remove_cv_ref_t< Either > >, decltype(_function(fcppt::move_if_rvalue< Either >(_either.get_success_unsafe()))) >
 Maps over the success type of an either. More...
 
template<typename Either , typename Function >
auto map_failure (Either &&_either, Function const &_function) -> fcppt::either::object< decltype(_function(fcppt::move_if_rvalue< Either >(_either.get_failure_unsafe()))), fcppt::either::success_type< fcppt::type_traits::remove_cv_ref_t< Either > > >
 Maps over the failure type of an either. More...
 
template<typename Either , typename FailureFunction , typename SuccessFunction >
auto match (Either &&_either, FailureFunction const &_failure_function, SuccessFunction const &_success_function) -> decltype(_success_function(fcppt::move_if_rvalue< Either >(_either.get_success_unsafe())))
 Matches on the two cases of an either. More...
 
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)
 
template<typename ResultContainer , typename Source >
fcppt::either::object< fcppt::either::failure_type< fcppt::type_traits::value_type< fcppt::type_traits::remove_cv_ref_t< Source > > >, ResultContainer > sequence (Source &&_source)
 Sequences a container of eithers. More...
 
template<typename Either >
fcppt::optional::object< fcppt::either::success_type< fcppt::type_traits::remove_cv_ref_t< Either > >> success_opt (Either &&_either)
 Returns the success type as an optional. More...
 
template<typename Either , typename MakeException >
auto to_exception (Either &&_either, MakeException const _make_exception) -> decltype(fcppt::move_if_rvalue< Either >(_either.get_success_unsafe()))
 Returns the success value contained in an either or throws an exception. More...
 
template<typename Exception , typename Function , typename ToException >
FCPPT_PP_PUSH_WARNING auto try_call (Function const &_function, ToException const &_to_exception) -> fcppt::either::object< decltype(_to_exception(std::declval< Exception >())), decltype(_function()) >
 Catches exceptions of a function call and puts the result in an either. More...
 

Detailed Description

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

Function Documentation

◆ operator<<()

template<typename Failure , typename Success , typename Ch , typename Traits >
std::basic_ostream< Ch, Traits>& fcppt::either::operator<< ( std::basic_ostream< Ch, Traits > &  _stream,
fcppt::either::object< Failure, Success > const &  _either 
)