GrPPI  1.0
Generic and Reusable Parallel Pattern Interface
map.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Universidad Carlos III de Madrid
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef GRPPI_MAP_H
17 #define GRPPI_MAP_H
18 
19 #include <utility>
20 
22 #include "common/iterator_traits.h"
23 
24 namespace grppi {
25 
46 template<typename Execution, typename ...InputIterators, typename InputIt,
47  typename OutputIt, typename Transformer,
48  requires_iterators<InputIterators...> = 0,
49  requires_iterator<InputIt> = 0,
50  requires_iterator<OutputIt> = 0>
51 void map(const Execution & ex, std::tuple<InputIterators...> firsts,
52  InputIt last, OutputIt first_out,
53  Transformer transform_op)
54 {
55  static_assert(supports_map<Execution>(),
56  "map not supported on execution type");
57  ex.map(firsts, first_out,
58  std::distance(std::get<0>(firsts),last), transform_op);
59 }
60 
61 
62 
74 template<typename Execution, typename ...InputIterators,
75  typename OutputIt, typename Transformer,
76  requires_iterators<InputIterators...> = 0,
77  requires_iterator<OutputIt> = 0>
78 void map(const Execution & ex, std::tuple<InputIterators...> firsts,
79  std::size_t range, OutputIt first_out,
80  Transformer transformer_op)
81 {
82  static_assert(supports_map<Execution>(),
83  "map not supported on execution type");
84  ex.map(firsts, first_out, range, transformer_op);
85 }
86 
98 template <typename Execution, typename InputIt, typename OutputIt,
99  typename Transformer,
100  requires_iterator<InputIt> = 0,
101  requires_iterator<OutputIt> = 0>
102 void map(const Execution & ex,
103  InputIt first, InputIt last, OutputIt first_out,
104  Transformer transform_op)
105 {
106  static_assert(supports_map<Execution>(),
107  "map not supported on execution type");
108  ex.map(make_tuple(first), first_out,
109  std::distance(first, last), transform_op);
110 }
111 
125 template <typename Execution, typename InputIt, typename OutputIt, typename Transformer,
126  typename ... OtherInputIts,
127  requires_iterator<InputIt> = 0,
128  requires_iterator<OutputIt> = 0>
129 [[deprecated("This version of the interface is deprecated.\n"
130  "If you want to use multiple inputs, use a tuple instead.")]]
131 void map(const Execution & ex,
132  InputIt first, InputIt last, OutputIt first_out,
133  Transformer transform_op,
134  OtherInputIts ... other_firsts)
135 {
136  static_assert(supports_map<Execution>(),
137  "map not supported on execution type");
138  ex.map(make_tuple(first,other_firsts...), first_out,
139  std::distance(first,last), transform_op);
140 }
141 
146 }
147 
148 #endif
void map(const Execution &ex, std::tuple< InputIterators... > firsts, InputIt last, OutputIt first_out, Transformer transform_op)
Invoke Map pattern on a data sequence.
Definition: map.h:51
Definition: callable_traits.h:21
std::enable_if_t< are_iterators< T... >, int > requires_iterators
Definition: iterator_traits.h:59