libzypp 17.38.5
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 >
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 >
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
Definition ansi.h:855
auto redo_while(Task &&todo, Pred &&until)
Definition redo.h:65
auto operator()(Arg &&arg)
Definition redo.h:49
RedoWhileHelper(T &&t, P &&p)
Definition redo.h:44
static auto create(T &&t, P &&p)
Definition redo.h:54
static auto execute(Task task, Pred pred, T &&arg)
Definition redo.h:30