libzypp 17.38.5

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/ng/meta/TypeTraits>
19#include <zypp-core/ng/meta/Functional>
20#include <algorithm>
21#include <zypp-core/ng/pipelines/operators.h>
22
23 namespace zyppng {
24
25 namespace detail {
26
27 template <typename ElementType, typename Fn, typename = void>
28 struct TransformImpl;
29
30 template <typename ElementType, typename Fn, typename>
31 struct TransformImpl {
32
33 using Ret = std::invoke_result_t<Fn, ElementType>;
34
35 template < template< class, class... > class Container,
36 typename Transformation = Fn,
37 typename ...CArgs >
38 static inline Container<Ret> execute( Container<ElementType, CArgs...>&& val, Transformation &&transformation )
39 {
40 Container<Ret> res;
41 std::transform( std::make_move_iterator(val.begin()), std::make_move_iterator(val.end()), std::back_inserter(res), std::forward<Transformation>(transformation) );
42 return res;
43 }
44
45 template < template< class, class... > class Container,
46 typename Transformation = Fn,
47 typename ...CArgs >
48 static inline Container<Ret> execute(const Container<ElementType, CArgs...>& val, Transformation &&transformation )
49 {
50 Container<Ret> res;
51 std::transform( val.begin(), val.end(), std::back_inserter(res), std::forward<Transformation>(transformation) );
52 return res;
53 }
54 };
55
56
57 }
58
59 template < template< class, class... > class Container,
60 typename Msg,
61 typename Transformation,
62 typename Ret = std::result_of_t<Transformation(Msg)>,
63 typename ...CArgs >
64 auto transform( Container<Msg, CArgs...>&& val, Transformation &&transformation )
65{
66 return detail::TransformImpl<Msg,Transformation>::execute( std::move(val), std::forward<Transformation>(transformation));
67}
68
69 template < template< class, class... > class Container,
70 typename Msg,
71 typename Transformation,
72 typename Ret = std::result_of_t<Transformation(Msg)>,
73 typename ...CArgs >
74 auto transform( const Container<Msg, CArgs...>& val, Transformation &&transformation )
75{
76 return detail::TransformImpl<Msg,Transformation>::execute( val, std::forward<Transformation>(transformation));
77}
78
79 namespace operators {
80
81 namespace detail {
82 template <typename Transformation, typename sfinae = void >
83 struct transform_helper {
84 Transformation function;
85
86 template< class Container >
87 auto operator()( Container&& arg ) {
88 return zyppng::transform( std::forward<Container>(arg), function );
89 }
90 };
91 }
92
93
94 template <typename Transformation>
95 auto transform(Transformation&& transformation)
96 {
97 return detail::transform_helper<Transformation>{
98 std::forward<Transformation>(transformation)};
99 }
100}
101
102}
103
104
105#ifdef ZYPP_ENABLE_ASYNC
106#include <zypp-core/ng/async/pipelines/transform.h>
107#endif
108
109
110#endif
std::result_of_t
typename result_of< T >::type result_of_t
Definition TypeTraits.h:51
zyppng::detail
Definition reporthelper.h:31
zyppng::operators::detail
Definition transform.h:81
zyppng::operators::transform
auto transform(Transformation &&transformation)
Definition transform.h:95
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::transform
auto transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Definition transform.h:64
zyppng::detail::TransformImpl
Definition transform.h:31
zyppng::detail::TransformImpl::execute
static Container< Ret > execute(const Container< ElementType, CArgs... > &val, Transformation &&transformation)
Definition transform.h:48
zyppng::detail::TransformImpl::execute
static Container< Ret > execute(Container< ElementType, CArgs... > &&val, Transformation &&transformation)
Definition transform.h:38
zyppng::detail::TransformImpl::Ret
std::invoke_result_t< Fn, ElementType > Ret
Definition transform.h:33
zyppng::operators::detail::transform_helper
Definition transform.h:83
zyppng::operators::detail::transform_helper::operator()
auto operator()(Container &&arg)
Definition transform.h:87
zyppng::operators::detail::transform_helper::function
Transformation function
Definition transform.h:84