libzypp 17.37.10

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>
21#include <zypp-core/zyppng/pipelines/wait.h>
22#include <algorithm>
23
24 namespace zyppng {
25
26 template < 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
38 template < 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
50 namespace detail {
51 template <typename Transformation >
52 struct transform_helper {
53 Transformation function;
54
55 template< class Container >
56 auto operator()( Container&& arg ) {
57 if constexpr ( detail::is_sync_monad_cb_with_async_res_v<Transformation, typename Container::value_type> ) {
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
67 namespace operators {
68
69 template <typename Transformation>
70 auto transform(Transformation&& transformation)
71 {
72 return detail::transform_helper<Transformation>{
73 std::forward<Transformation>(transformation)};
74 }
75}
76
77}
78
79#endif
std::result_of_t
typename result_of< T >::type result_of_t
Definition TypeTraits.h:51
zyppng::detail::is_sync_monad_cb_with_async_res_v
constexpr bool is_sync_monad_cb_with_async_res_v
Definition asyncresult.h:90
zyppng::operators
Definition asyncresult.h:279
zyppng::operators::transform
auto transform(Transformation &&transformation)
Definition transform.h:70
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::transform
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Definition transform.h:31
zyppng::waitFor
auto waitFor()
Definition wait.h:129
zyppng::detail::transform_helper
Definition transform.h:52
zyppng::detail::transform_helper::operator()
auto operator()(Container &&arg)
Definition transform.h:56
zyppng::detail::transform_helper::function
Transformation function
Definition transform.h:53
wait.h