libzypp  17.35.11
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 
24 namespace zyppng {
25 
26 template < template< class, class... > class Container,
27  typename Msg,
28  typename Transformation,
30  typename ...CArgs >
31 Container<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,
42  typename ...CArgs >
43 Container<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 >
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  {
73  std::forward<Transformation>(transformation)};
74  }
75 }
76 
77 }
78 
79 #endif
auto transform(Transformation &&transformation)
Definition: transform.h:70
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Definition: transform.h:31
typename result_of< T >::type result_of_t
Definition: TypeTraits.h:51
auto waitFor()
Definition: wait.h:129
auto operator()(Container &&arg)
Definition: transform.h:56