16#ifndef ZYPP_ZYPPNG_MONADIC_EXPECTED_H
17#define ZYPP_ZYPPNG_MONADIC_EXPECTED_H
19#include <zypp-core/zyppng/meta/Functional>
20#include <zypp-core/zyppng/pipelines/AsyncResult>
21#include <zypp-core/zyppng/pipelines/Wait>
22#include <zypp-core/zyppng/pipelines/Transform>
26 template<
typename T,
typename E = std::exception_ptr>
68 new (&
m_value) T( std::move(other.m_value) );
70 new (&
m_error) E( std::move(other.m_error) );
84 if (other.m_isValid) {
91 auto temp = std::move(other.m_error);
93 new (&other.m_value) T(std::move(
m_value));
95 new (&
m_error) E(std::move(temp));
100 if (other.m_isValid) {
114 template <
typename... ConsParams>
121 new(&result.
m_value) T(std::forward<ConsParams>(params)...);
125 template <
typename... ConsParams>
132 new(&result.
m_error) E(std::forward<ConsParams>(params)...);
147 # define THROW_MSG_IF_EXCEPTIONS_ARE_ENABLED(WHAT) std::terminate()
149 # define THROW_MSG_IF_EXCEPTIONS_ARE_ENABLED(WHAT) throw std::logic_error(WHAT)
179 if constexpr ( std::is_same_v<E, std::exception_ptr> ) {
180 std::rethrow_exception (
error() );
195 if constexpr ( std::is_same_v<E, std::exception_ptr>() ) {
196 std::rethrow_exception (
error() );
210 const T &operator* ()
const
220 const T *operator-> ()
const
237 #undef THROW_IF_EXCEPTIONS_ARE_ENABLED
239 template <
typename F>
288 new (&
m_error) E(std::move(other.m_error));
302 if (other.m_isValid) {
309 auto temp = std::move(other.m_error);
311 new (&
m_error) E(std::move(temp));
316 if (other.m_isValid) {
340 template <
typename... ConsParams>
347 new(&result.
m_error) E(std::forward<ConsParams>(params)...);
362 # define THROW_IF_EXCEPTIONS_ARE_ENABLED(WHAT) std::terminate()
364 # define THROW_IF_EXCEPTIONS_ARE_ENABLED(WHAT) throw std::logic_error(WHAT)
385 if constexpr ( std::is_same_v<E, std::exception_ptr> ) {
386 std::rethrow_exception (
error() );
396 template <
typename Type,
typename Err = std::exception_ptr >
408 template <
typename Function,
typename ArgType>
411 template <
typename T>
418 template <
typename T
426 if constexpr ( std::is_same_v<T,void> )
432 return ResultType::error(exp.
error());
438 template <
typename T
446 if constexpr ( std::is_same_v<T,void> )
449 return std::invoke( std::forward<Function>(f), std::move(exp.get()) );
452 return ResultType::error( std::move(exp.error()) );
458 template <
typename T
475 template <
typename T
483 return std::invoke( std::forward<Function>(f), std::move(exp.error()) );
497 template <
template<
class,
class... >
class Container,
501 std::enable_if_t<!std::is_same_v<void, T>, expected<Container<T>,E>>
collect( Container<expected<T, E>, CArgs...>&& in ) {
503 for(
auto &v : in ) {
506 res.push_back( std::move(v.get()) );
515 template <
template<
class,
class... >
class Container,
519 std::enable_if_t<std::is_same_v<void, T>, expected<T, E>>
collect( Container<expected<T, E>, CArgs...>&& in ) {
520 for(
auto &v : in ) {
527 template <
typename T
534 const auto &val = exp.
get();
540 template <
typename T
547 const auto &err = exp.
error();
556 template <
typename Callback>
560 template<
typename T,
typename E >
565 template<
typename T,
typename E >
571 template <
typename Callback>
575 template<
typename T,
typename E >
580 template<
typename T,
typename E >
586 template <
typename Callback>
590 template<
typename T,
typename E >
596 template <
typename Callback>
600 template<
typename T,
typename E >
607 template <
typename T >
609 return collect( std::forward<T>(in) );
614 namespace operators {
615 template <
typename Fun>
618 std::forward<Fun>(function)
622 template <
typename Fun>
625 std::forward<Fun>(function)
629 template <
typename Fun>
632 std::forward<Fun>(function)
636 template <
typename Fun>
639 std::forward<Fun>(function)
643 template <
typename Fun>
646 std::forward<Fun>(function)
660 template <
template<
class,
class... >
class Container,
662 typename Transformation,
680 Container<typename Ret::value_type> results;
681 for (
auto &v : in ) {
682 auto res = f(std::move(v));
684 results.push_back( std::move(res.get()) );
694 template <
typename Fun>
697 template <
typename T>
705 template <
typename Transformation>
static expected success()
expected(expected &&other) 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)
std::pair< zypp::ServiceInfo, RepoInfoList > m_value
expected(const expected &other)
void swap(expected &other) noexcept
std::pair< zypp::ServiceInfo, RepoInfoList > value_type
#define THROW_MSG_IF_EXCEPTIONS_ARE_ENABLED(WHAT)
#define THROW_IF_EXCEPTIONS_ARE_ENABLED(WHAT)
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)
constexpr bool is_async_op_v
std::conjunction< has_value_type< remove_smart_ptr_t< T > >, is_asyncop_type< remove_smart_ptr_t< T > > > is_async_op
bool waitForCanContinueExpected(const expected< T > &value)
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)
auto transform_collect(Container< Msg, CArgs... > &&in, Transformation &&f)
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
typename remove_smart_ptr< T >::type remove_smart_ptr_t
static expected< std::decay_t< Type >, Err > make_expected_success(Type &&t)
ResultType or_else(const expected< T, E > &exp, Function &&f)
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)
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
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)
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)