libzypp 17.37.17
transform.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
15#ifndef ZYPP_ZYPPNG_MONADIC_TRANSFORM_H
16#define ZYPP_ZYPPNG_MONADIC_TRANSFORM_H
17
18#include <zypp-core/zyppng/meta/TypeTraits>
19#include <zypp-core/zyppng/meta/Functional>
20#include <zypp-core/zyppng/pipelines/AsyncResult>
22#include <algorithm>
23
24namespace zyppng {
25
26template < template< class, class... > class Container,
27 typename Msg,
28 typename Transformation,
29 typename Ret = std::result_of_t<Transformation(Msg)>,
30 typename ...CArgs >
31Container<Ret> transform( Container<Msg, CArgs...>&& val, Transformation &&transformation )
32{
33 Container<Ret> res;
34 std::transform( std::make_move_iterator(val.begin()), std::make_move_iterator(val.end()), std::back_inserter(res), std::forward<Transformation>(transformation) );
35 return res;
36}
37
38template < template< class, class... > class Container,
39 typename Msg,
40 typename Transformation,
41 typename Ret = std::result_of_t<Transformation(Msg)>,
42 typename ...CArgs >
43Container<Ret> transform( const Container<Msg, CArgs...>& val, Transformation &&transformation )
44{
45 Container<Ret> res;
46 std::transform( val.begin(), val.end(), std::back_inserter(res), std::forward<Transformation>(transformation) );
47 return res;
48}
49
50namespace detail {
51 template <typename Transformation >
53 Transformation function;
54
55 template< class Container >
56 auto operator()( Container&& arg ) {
58 using namespace zyppng::operators;
59 return zyppng::transform( std::forward<Container>(arg), function ) | zyppng::waitFor();
60 } else {
61 return zyppng::transform( std::forward<Container>(arg), function );
62 }
63 }
64 };
65}
66
67namespace operators {
68
69 template <typename Transformation>
70 auto transform(Transformation&& transformation)
71 {
73 std::forward<Transformation>(transformation)};
74 }
75}
76
77}
78
79#endif
typename result_of< T >::type result_of_t
Definition TypeTraits.h:51
constexpr bool is_sync_monad_cb_with_async_res_v
Definition asyncresult.h:90
auto transform(Transformation &&transformation)
Definition transform.h:70
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Definition transform.h:31
auto waitFor()
Definition wait.h:129
auto operator()(Container &&arg)
Definition transform.h:56