libzypp 17.37.17
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
24namespace 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;
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;
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:
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
Definition Arch.h:364
typename make_void< Ts... >::type void_t
Definition type_traits.h:12
typename result_of< T >::type result_of_t
Definition TypeTraits.h:51
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
auto lift(Fun &&func)
Definition lift.h:74
LiftedFun _fun
Definition lift.h:42
lifter(LiftedFun &&fun)
Definition lift.h:30
lifter(lifter &&)=default
Ret operator()(std::pair< T1, T2 > &&data)
Definition lift.h:38