libzypp 17.37.10

lift.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPPNG_MONADIC_LIFT_H_INCLUDED
15#define ZYPPNG_MONADIC_LIFT_H_INCLUDED
16
17#include <utility>
18#include <memory>
19#include <iostream>
20
21#include <zypp-core/zyppng/meta/Functional>
22#include <zypp-core/zyppng/pipelines/AsyncResult>
23
24 namespace zyppng {
25
26 namespace detail {
27 template <typename LiftedFun, typename extra = void >
28 struct lifter {
29
30 lifter( LiftedFun &&fun ) : _fun(std::move(fun)) {}
31 lifter( lifter && ) = default;
32 ~lifter(){}
33
34 template< typename T1
35 , typename T2
36 , typename Ret = std::pair<std::result_of_t<LiftedFun(T1)>, T2>
37 >
38 Ret operator()( std::pair<T1, T2> &&data ) {
39 return std::make_pair( std::invoke( _fun, std::move(data.first) ), std::move(data.second) );
40 }
41 private:
42 LiftedFun _fun;
43 };
44
45 template < typename AsyncOp >
46 struct lifter< std::shared_ptr<AsyncOp>, std::void_t< std::enable_if_t< zyppng::detail::is_async_op<AsyncOp>::value > > > {
47
48 using LiftedFun = std::shared_ptr<AsyncOp>;
49
50 lifter( LiftedFun &&fun ) : _fun(std::move(fun)) {}
51 lifter( lifter && ) = default;
52 ~lifter(){}
53
54 template< typename T1
55 , typename T2
56 >
57 auto operator()( std::pair<T1, T2> &&data ) {
58
59 using namespace zyppng;
60 using namespace zyppng::operators;
61
62 return std::move(data.first)
63 | ( std::move(_fun) )
64 | [ other = std::move(data.second)]( auto && res ) mutable {
65 return std::make_pair( std::forward<decltype (res)>(res), std::move(other) );
66 };
67 }
68 private:
69 LiftedFun _fun;
70 };
71 }
72
73 template< typename Fun >
74 auto lift ( Fun && func ) {
75 return detail::lifter<Fun>( std::forward<Fun>(func) );
76 }
77
78}
79
80#endif
shared_ptr
std
Definition Arch.h:364
std::void_t
typename make_void< Ts... >::type void_t
Definition type_traits.h:12
std::result_of_t
typename result_of< T >::type result_of_t
Definition TypeTraits.h:51
std::invoke
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::type invoke(Functor &&f, Args &&... args)
Definition functional.h:32
zyppng::detail
Definition reporthelper.h:31
zyppng::operators
Definition asyncresult.h:279
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::lift
auto lift(Fun &&func)
Definition lift.h:74
zyppng::detail::lifter< std::shared_ptr< AsyncOp >, std::void_t< std::enable_if_t< zyppng::detail::is_async_op< AsyncOp >::value > > >::~lifter
~lifter()
Definition lift.h:52
zyppng::detail::lifter< std::shared_ptr< AsyncOp >, std::void_t< std::enable_if_t< zyppng::detail::is_async_op< AsyncOp >::value > > >::LiftedFun
std::shared_ptr< AsyncOp > LiftedFun
Definition lift.h:48
zyppng::detail::lifter< std::shared_ptr< AsyncOp >, std::void_t< std::enable_if_t< zyppng::detail::is_async_op< AsyncOp >::value > > >::operator()
auto operator()(std::pair< T1, T2 > &&data)
Definition lift.h:57
zyppng::detail::lifter< std::shared_ptr< AsyncOp >, std::void_t< std::enable_if_t< zyppng::detail::is_async_op< AsyncOp >::value > > >::lifter
lifter(LiftedFun &&fun)
Definition lift.h:50
zyppng::detail::lifter< std::shared_ptr< AsyncOp >, std::void_t< std::enable_if_t< zyppng::detail::is_async_op< AsyncOp >::value > > >::_fun
LiftedFun _fun
Definition lift.h:69
zyppng::detail::lifter< std::shared_ptr< AsyncOp >, std::void_t< std::enable_if_t< zyppng::detail::is_async_op< AsyncOp >::value > > >::lifter
lifter(lifter &&)=default
zyppng::detail::lifter
Definition lift.h:28
zyppng::detail::lifter::_fun
LiftedFun _fun
Definition lift.h:42
zyppng::detail::lifter::lifter
lifter(LiftedFun &&fun)
Definition lift.h:30
zyppng::detail::lifter::lifter
lifter(lifter &&)=default
zyppng::detail::lifter::~lifter
~lifter()
Definition lift.h:32
zyppng::detail::lifter::operator()
Ret operator()(std::pair< T1, T2 > &&data)
Definition lift.h:38