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

libzypp 17.38.13

redo.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_REDO_H_INCLUDED
15#define ZYPPNG_MONADIC_REDO_H_INCLUDED
16
17#include <zypp-core/ng/meta/FunctionTraits>
18#include <zypp-core/ng/meta/TypeTraits>
19#include <zypp-core/ng/meta/Functional>
20#include <zypp-core/ng/pipelines/operators.h>
21
22namespace zyppng {
23
24 namespace detail {
25
26 template< typename Task, typename Pred, typename Arg, typename = void >
27 struct RedoWhileImpl
28 {
29 template <typename T = Arg>
30 static auto execute( Task task, Pred pred, T &&arg ) {
31 Arg store = std::forward<T>(arg);
32 do {
33 auto res = task ( Arg(store) );
34 if ( !pred( res ) )
35 return std::move(res);
36 } while( true );
37 }
38 };
39
40 template< typename Task, typename Pred >
41 struct RedoWhileHelper
42 {
43 template <typename T, typename P>
44 RedoWhileHelper( T &&t, P &&p ) :
45 _task( std::forward<T>(t) )
46 , _pred( std::forward<P>(p) ) {}
47
48 template <typename Arg>
49 auto operator()( Arg &&arg ) {
50 return RedoWhileImpl<Task,Pred, Arg>::execute( std::move(_task), std::move(_pred), std::forward<Arg>(arg) );
51 }
52
53 template <typename T, typename P>
54 static auto create ( T &&t, P &&p ) {
55 return RedoWhileImpl( std::forward<T>(t), std::forward<P>(p));
56 }
57
58 private:
59 Task _task;
60 Pred _pred;
61 };
62 }
63
64 template <typename Task, typename Pred>
65 auto redo_while ( Task &&todo, Pred &&until ) {
66 return detail::RedoWhileHelper<Task,Pred>::create( std::forward<Task>(todo), std::forward<Pred>(until) );
67 }
68
69}
70
71#ifdef ZYPP_ENABLE_ASYNC
72#include <zypp-core/ng/async/pipelines/redo.hpp>
73#endif
74
75#endif
std
Definition ansi.h:855
zyppng::detail
Definition reporthelper.h:31
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::redo_while
auto redo_while(Task &&todo, Pred &&until)
Definition redo.h:65
zyppng::detail::RedoWhileHelper::_pred
Pred _pred
Definition redo.h:60
zyppng::detail::RedoWhileHelper::_task
Task _task
Definition redo.h:59
zyppng::detail::RedoWhileHelper::operator()
auto operator()(Arg &&arg)
Definition redo.h:49
zyppng::detail::RedoWhileHelper::RedoWhileHelper
RedoWhileHelper(T &&t, P &&p)
Definition redo.h:44
zyppng::detail::RedoWhileHelper::create
static auto create(T &&t, P &&p)
Definition redo.h:54
zyppng::detail::RedoWhileImpl
Definition redo.h:28
zyppng::detail::RedoWhileImpl::execute
static auto execute(Task task, Pred pred, T &&arg)
Definition redo.h:30