libzypp: zypp-core/ng/pipelines/lift.h Source File

libzypp 17.38.14

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
19#include <zypp-core/ng/meta/Functional>
20#include <zypp-core/ng/async/task.h>
21#include <zypp-core/ng/pipelines/operators.h>
22
23namespace zyppng {
24
25 namespace detail {
26
27 template <typename LiftedFun, typename T1, typename T2, typename = void >
28 struct LiftImpl {
29 static auto execute( LiftedFun fun, std::pair<T1, T2> &&data ) {
30 return std::make_pair( std::invoke( fun, std::move(data.first) ), std::move(data.second) );
31 }
32 };
33
34 template <typename LiftedFun >
35 struct lifter {
36
37 lifter( LiftedFun &&fun ) : _fun(std::move(fun)) {}
38 lifter( lifter && ) = default;
39 ~lifter(){}
40
41 template< typename T1
42 , typename T2
43 >
44 auto operator()( std::pair<T1, T2> &&data ) {
45 return LiftImpl<LiftedFun, T1, T2>::execute( std::move(_fun), std::move(data) );
46 }
47 private:
48 LiftedFun _fun;
49 };
50 }
51
52 template< typename Fun >
53 auto lift ( Fun && func ) {
54 return detail::lifter<Fun>( std::forward<Fun>(func) );
55 }
56
57}
58
59
60#ifdef ZYPP_ENABLE_ASYNC
61#include <zypp-core/ng/async/pipelines/lift.hpp>
62#endif
63
64#endif
std
Definition ansi.h:855
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
Definition MediaNetworkRequestExecutor.h:16
zyppng::lift
auto lift(Fun &&func)
Definition lift.h:53
zyppng::detail::LiftImpl
Definition lift.h:28
zyppng::detail::LiftImpl::execute
static auto execute(LiftedFun fun, std::pair< T1, T2 > &&data)
Definition lift.h:29
zyppng::detail::lifter
Definition lift.h:35
zyppng::detail::lifter::lifter
lifter(lifter &&)=default
zyppng::detail::lifter::operator()
auto operator()(std::pair< T1, T2 > &&data)
Definition lift.h:44
zyppng::detail::lifter::~lifter
~lifter()
Definition lift.h:39
zyppng::detail::lifter::_fun
LiftedFun _fun
Definition lift.h:48
zyppng::detail::lifter::lifter
lifter(LiftedFun &&fun)
Definition lift.h:37