16#ifndef ZYPP_ZYPPNG_MONADIC_EXPECTED_H
17#define ZYPP_ZYPPNG_MONADIC_EXPECTED_H
21#include <zypp-core/ng/meta/Functional>
23#include <zypp-core/ng/pipelines/operators.h>
31 template <
typename E = T>
55 template<
typename T,
typename E = std::exception_ptr>
90 new (&
m_value) T( std::move(v) );
100 new(&
m_error) E(std::move(err.error()));
117 new (&
m_value) T( std::move(other.m_value) );
119 new (&
m_error) E( std::move(other.m_error) );
123 template <
class G = E >
136 template<
class U = std::remove_cv_t<T> >
147 if (other.m_isValid) {
154 auto temp = std::move(other.m_error);
156 new (&other.m_value) T(std::move(
m_value));
158 new (&
m_error) E(std::move(temp));
163 if (other.m_isValid) {
177 template <
typename... ConsParams>
184 new(&result.
m_value) T(std::forward<ConsParams>(params)...);
188 template <
typename... ConsParams>
195 new(&result.
m_error) E(std::forward<ConsParams>(params)...);
210 # define THROW_MSG_IF_EXCEPTIONS_ARE_ENABLED(WHAT) std::terminate()
212 # define THROW_MSG_IF_EXCEPTIONS_ARE_ENABLED(WHAT) throw std::logic_error(WHAT)
242 if constexpr ( std::is_same_v<E, std::exception_ptr> ) {
243 std::rethrow_exception (
error() );
258 if constexpr ( std::is_same_v<E, std::exception_ptr>() ) {
259 std::rethrow_exception (
error() );
273 const T &operator* ()
const
283 const T *operator-> ()
const
300 #undef THROW_IF_EXCEPTIONS_ARE_ENABLED
302 template <
typename F>
330 new(&
m_error) E(std::move(err.error()));
358 new (&
m_error) E(std::move(other.m_error));
368 template <
class G = E >
380 if (other.m_isValid) {
387 auto temp = std::move(other.m_error);
389 new (&
m_error) E(std::move(temp));
394 if (other.m_isValid) {
413 template <
typename... ConsParams>
420 new(&result.
m_error) E(std::forward<ConsParams>(params)...);
435 # define THROW_IF_EXCEPTIONS_ARE_ENABLED(WHAT) std::terminate()
437 # define THROW_IF_EXCEPTIONS_ARE_ENABLED(WHAT) throw std::logic_error(WHAT)
458 if constexpr ( std::is_same_v<E, std::exception_ptr> ) {
459 std::rethrow_exception (
error() );
469 template <
typename Type,
typename Err = std::exception_ptr >
481 template <
typename Function,
typename ArgType>
484 template <
typename T>
489 template<
typename ResultType>
491 template <
typename E>
492 static ResultType
error ( E &&err ) {
493 return ResultType::error( std::forward<E>(err) );
496 template <
typename Res>
498 return std::forward<Res>(exp);
502 template <
typename ResultType,
typename E>
507 template <
typename ResultType>
515 template <
typename T
523 if constexpr ( std::is_same_v<T,void> )
532 template <
typename T
540 if constexpr ( std::is_same_v<T,void> )
543 return std::invoke( std::forward<Function>(f), std::move(exp.get()) );
549 template <
typename T
563 template <
typename T
571 return std::invoke( std::forward<Function>(f), std::move(exp.error()) );
582 template <
template<
class,
class... >
class Container,
586 std::enable_if_t<!std::is_same_v<void, T>, expected<Container<T>,E>>
collect( Container<expected<T, E>, CArgs...>&& in ) {
588 for(
auto &v : in ) {
591 res.push_back( std::move(v.get()) );
600 template <
template<
class,
class... >
class Container,
604 std::enable_if_t<std::is_same_v<void, T>, expected<T, E>>
collect( Container<expected<T, E>, CArgs...>&& in ) {
605 for(
auto &v : in ) {
612 template <
typename T
619 const auto &val = exp.
get();
625 template <
typename T
632 const auto &err = exp.
error();
641 template <
typename Callback>
645 template<
typename T,
typename E >
650 template<
typename T,
typename E >
656 template <
typename Callback>
660 template<
typename T,
typename E >
665 template<
typename T,
typename E >
671 template <
typename Callback>
675 template<
typename T,
typename E >
681 template <
typename Callback>
685 template<
typename T,
typename E >
692 template <
typename T >
694 return collect( std::forward<T>(in) );
700 template <
typename Fun>
703 std::forward<Fun>(function)
707 template <
typename Fun>
710 std::forward<Fun>(function)
714 template <
typename Fun>
717 std::forward<Fun>(function)
721 template <
typename Fun>
724 std::forward<Fun>(function)
728 template <
typename Fun>
731 std::forward<Fun>(function)
745 template <
template<
class,
class... >
class Container,
747 typename Transformation,
753 Container<typename Ret::value_type> results;
754 for (
auto &v : in ) {
755 auto res = f(std::move(v));
757 results.push_back( std::move(res.get()) );
766 template <
typename Fun>
769 template <
typename T>
776 namespace operators {
777 template <
typename Transformation>
784#ifdef ZYPP_ENABLE_ASYNC
785#include <zypp-core/ng/async/pipelines/expected.hpp>
static expected success()
expected(expected &&other) noexcept
expected(unexpected< G > err) noexcept
expected(const expected &other)
static expected error(ConsParams &&...params)
void swap(expected &other) noexcept
expected(expected &&other) noexcept
static expected success(ConsParams &&...params)
std::exception_ptr m_error
std::exception_ptr error_type
static expected error(ConsParams &&...params)
expected(const unexpected< E > &err) noexcept
std::pair< zypp::ServiceInfo, RepoInfoList > m_value
expected(const expected &other)
void swap(expected &other) noexcept
std::pair< zypp::ServiceInfo, RepoInfoList > value_type
expected(unexpected< E > &&err) noexcept
expected & operator=(U &&v)
unexpected(unexpected &&)=default
unexpected & operator=(const unexpected &)=default
unexpected & operator=(unexpected &&)=default
unexpected(const unexpected &)=default
#define THROW_MSG_IF_EXCEPTIONS_ARE_ENABLED(WHAT)
#define THROW_IF_EXCEPTIONS_ARE_ENABLED(WHAT)
typename enable_if< B, T >::type enable_if_t
typename conditional< B, T, F >::type conditional_t
typename result_of< T >::type result_of_t
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::type invoke(Functor &&f, Args &&... args)
ResultType expected_forward(ResultType &&res)
bool waitForCanContinueExpected(const expected< T > &value)
ResultType expected_make_error(E &&error)
typename std::conditional_t< std::is_same_v< ArgType, void >, std::invoke_result< Function >, std::invoke_result< Function, ArgType > >::type mbind_cb_result_t
auto or_else(Fun &&function)
auto transform_collect(Transformation &&f)
auto and_then(Fun &&function)
auto inspect_err(Fun &&function)
detail::collect_helper collect()
auto inspect(Fun &&function)
auto mbind(Fun &&function)
std::enable_if_t< is_instance_of_v< expected, Ret >, expected< Container< typename Ret::value_type > > > transform_collect(Container< Msg, CArgs... > &&in, Transformation &&f)
static expected< std::decay_t< Type >, Err > make_expected_success(Type &&t)
ResultType or_else(const expected< T, E > &exp, Function &&f)
unexpected(E) -> unexpected< E >
ResultType and_then(const expected< T, E > &exp, Function &&f)
std::enable_if_t<!std::is_same_v< void, T >, expected< Container< T >, E > > collect(Container< expected< T, E >, CArgs... > &&in)
expected< T, E > inspect(expected< T, E > exp, Function &&f)
expected< T, E > inspect_err(expected< T, E > exp, Function &&f)
auto operator()(expected< T, E > &&exp)
auto operator()(const expected< T, E > &exp)
static ResultType forward(Res &&exp)
static ResultType error(E &&err)
auto operator()(expected< T, E > &&exp)
auto operator()(expected< T, E > &&exp)
auto operator()(const expected< T, E > &exp)
auto operator()(expected< T, E > &&exp)