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>
55 : m_isValid(other.m_isValid)
58 new (&m_value) T(other.
m_value);
60 new (&m_error) E(other.
m_error);
65 : m_isValid(other.m_isValid)
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) {
86 swap(m_value, other.m_value);
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));
96 std::swap(m_isValid, other.m_isValid);
100 if (other.m_isValid) {
108 swap(m_error, other.m_error);
109 std::swap(m_isValid, other.m_isValid);
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() );
237 #undef THROW_IF_EXCEPTIONS_ARE_ENABLED
239 template <
typename F>
273 : m_isValid(other.m_isValid)
278 new (&m_error) E(other.
m_error);
283 : m_isValid(other.m_isValid)
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));
312 std::swap(m_isValid, other.m_isValid);
316 if (other.m_isValid) {
324 swap(m_error, other.m_error);
325 std::swap(m_isValid, other.m_isValid);
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>
413 return value.is_valid();
418 template <
typename T
421 ,
typename ResultType = detail::mbind_cb_result_t<Function, T>
426 if constexpr ( std::is_same_v<T,void> )
432 return ResultType::error(
exp.error());
438 template <
typename T
441 ,
typename ResultType = detail::mbind_cb_result_t<Function, T>
446 if constexpr ( std::is_same_v<T,void> )
452 return ResultType::error( std::move(
exp.error()) );
458 template <
typename T
461 ,
typename ResultType = detail::mbind_cb_result_t<Function, E>
475 template <
typename T
478 ,
typename ResultType = detail::mbind_cb_result_t<Function, E>
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 >
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,
669 if constexpr ( detail::is_async_op_v<Ret> ) {
681 for (
auto &
v :
in ) {
682 auto res =
f(std::move(
v));
694 template <
typename Fun>
697 template <
typename T>
704 namespace operators {
705 template <
typename Transformation>
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
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)
static expected error(ConsParams &&...params)
expected(const expected &other)
void swap(expected &other) noexcept
#define THROW_MSG_IF_EXCEPTIONS_ARE_ENABLED(WHAT)
#define THROW_IF_EXCEPTIONS_ARE_ENABLED(WHAT)
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::typ invoke)(Functor &&f, Args &&... args)
typename conditional< B, T, F >::type conditional_t
typename result_of< T >::type result_of_t
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)
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)