STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
for_each_selectors.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Copyright (C) 2007-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
10 
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
31 // Written by Felix Putze.
32 
33 #ifndef _GLIBCXX_PARALLEL_FOR_EACH_SELECTORS_H
34 #define _GLIBCXX_PARALLEL_FOR_EACH_SELECTORS_H 1
35 
37 
38 namespace __gnu_parallel
39 {
41  template<typename _It>
43  {
48  };
49 
51  template<typename _It>
53  {
57  template<typename _Op>
58  bool
59  operator()(_Op& __o, _It __i)
60  {
61  __o(*__i);
62  return true;
63  }
64  };
65 
67  template<typename _It>
69  {
73  template<typename _Op>
74  bool
75  operator()(_Op& __o, _It __i)
76  {
77  *__i = __o();
78  return true;
79  }
80  };
81 
83  template<typename _It>
85  {
89  template<typename _ValueType>
90  bool
91  operator()(_ValueType& __v, _It __i)
92  {
93  *__i = __v;
94  return true;
95  }
96  };
97 
99  template<typename _It>
101  {
105  template<typename _Op>
106  bool
107  operator()(_Op& __o, _It __i)
108  {
109  *__i.second = __o(*__i.first);
110  return true;
111  }
112  };
113 
115  template<typename _It>
117  {
121  template<typename _Op>
122  bool
123  operator()(_Op& __o, _It __i)
124  {
125  *__i._M_third = __o(*__i._M_first, *__i._M_second);
126  return true;
127  }
128  };
129 
131  template<typename _It, typename _Tp>
133  {
135  const _Tp& __new_val;
136 
139  explicit
140  __replace_selector(const _Tp &__new_val) : __new_val(__new_val) {}
141 
145  bool
146  operator()(_Tp& __v, _It __i)
147  {
148  if (*__i == __v)
149  *__i = __new_val;
150  return true;
151  }
152  };
153 
155  template<typename _It, typename _Op, typename _Tp>
157  {
159  const _Tp& __new_val;
160 
163  explicit
164  __replace_if_selector(const _Tp &__new_val) : __new_val(__new_val) { }
165 
169  bool
170  operator()(_Op& __o, _It __i)
171  {
172  if (__o(*__i))
173  *__i = __new_val;
174  return true;
175  }
176  };
177 
179  template<typename _It, typename _Diff>
181  {
186  template<typename _ValueType>
187  _Diff
188  operator()(_ValueType& __v, _It __i)
189  { return (__v == *__i) ? 1 : 0; }
190  };
191 
193  template<typename _It, typename _Diff>
195  {
200  template<typename _Op>
201  _Diff
202  operator()(_Op& __o, _It __i)
203  { return (__o(*__i)) ? 1 : 0; }
204  };
205 
207  template<typename _It>
209  {
214  template<typename _Op>
215  typename std::iterator_traits<_It>::value_type
216  operator()(_Op __o, _It __i)
217  { return *__i; }
218  };
219 
221  template<typename _It, typename _It2, typename _Tp>
223  {
226 
229 
233  explicit
234  __inner_product_selector(_It __b1, _It2 __b2)
235  : __begin1_iterator(__b1), __begin2_iterator(__b2) { }
236 
241  template<typename _Op>
242  _Tp
243  operator()(_Op __mult, _It __current)
244  {
245  typename std::iterator_traits<_It>::difference_type __position
246  = __current - __begin1_iterator;
247  return __mult(*__current, *(__begin2_iterator + __position));
248  }
249  };
250 
252  template<typename _It>
254  {
259  template<typename _Op>
260  _It
261  operator()(_Op __o, _It __i)
262  { return __i; }
263  };
264 
268  template<typename _It>
270  : public __generic_for_each_selector<_It>
271  {
272  template<typename _Op>
273  bool
274  operator()(_Op& __o, _It __i)
275  {
276  typename _It::first_type __go_back_one = __i.first;
277  --__go_back_one;
278  *__i.second = __o(*__i.first, *__go_back_one);
279  return true;
280  }
281  };
282 
288  struct _Nothing
289  {
292  template<typename _It>
293  void
294  operator()(_It __i) { }
295  };
296 
299  {
300  bool
301  operator()(bool, bool) const
302  { return true; }
303  };
304 
306  template<typename _Compare, typename _It>
308  {
309  _Compare& __comp;
310 
311  explicit
312  __min_element_reduct(_Compare &__c) : __comp(__c) { }
313 
314  _It
315  operator()(_It __x, _It __y)
316  { return (__comp(*__x, *__y)) ? __x : __y; }
317  };
318 
320  template<typename _Compare, typename _It>
322  {
323  _Compare& __comp;
324 
325  explicit
326  __max_element_reduct(_Compare& __c) : __comp(__c) { }
327 
328  _It
329  operator()(_It __x, _It __y)
330  { return (__comp(*__x, *__y)) ? __y : __x; }
331  };
332 
334  template<typename _BinOp>
336  {
337  _BinOp& __binop;
338 
339  explicit
340  __accumulate_binop_reduct(_BinOp& __b) : __binop(__b) { }
341 
342  template<typename _Result, typename _Addend>
343  _Result
344  operator()(const _Result& __x, const _Addend& __y)
345  { return __binop(__x, __y); }
346  };
347 }
348 
349 #endif /* _GLIBCXX_PARALLEL_FOR_EACH_SELECTORS_H */
bool operator()(_Tp &__v, _It __i)
Functor execution.
Definition: for_each_selectors.h:146
__accumulate_binop_reduct(_BinOp &__b)
Definition: for_each_selectors.h:340
_Tp operator()(_Op __mult, _It __current)
Functor execution.
Definition: for_each_selectors.h:243
__inner_product_selector(_It __b1, _It2 __b2)
Constructor.
Definition: for_each_selectors.h:234
_Compare & __comp
Definition: for_each_selectors.h:323
void operator()(_It __i)
Functor execution.
Definition: for_each_selectors.h:294
Reduction for finding the maximum element, using a comparator.
Definition: for_each_selectors.h:321
_Diff operator()(_Op &__o, _It __i)
Functor execution.
Definition: for_each_selectors.h:202
_It2 __begin2_iterator
Begin iterator of second sequence.
Definition: for_each_selectors.h:228
const _Tp & __new_val
Value to replace with.
Definition: for_each_selectors.h:159
bool operator()(_Op &__o, _It __i)
Functor execution.
Definition: for_each_selectors.h:75
_Diff operator()(_ValueType &__v, _It __i)
Functor execution.
Definition: for_each_selectors.h:188
__replace_if_selector(const _Tp &__new_val)
Constructor.
Definition: for_each_selectors.h:164
bool operator()(bool, bool) const
Definition: for_each_selectors.h:301
Generic __selector for embarrassingly parallel functions.
Definition: for_each_selectors.h:42
_It __begin1_iterator
Begin iterator of first sequence.
Definition: for_each_selectors.h:225
std::replace() selector.
Definition: for_each_selectors.h:156
std::inner_product() selector.
Definition: for_each_selectors.h:222
Reduction for finding the maximum element, using a comparator.
Definition: for_each_selectors.h:307
Functor doing nothing.
Definition: for_each_selectors.h:288
_Compare & __comp
Definition: for_each_selectors.h:309
__min_element_reduct(_Compare &__c)
Definition: for_each_selectors.h:312
Selector that just returns the passed iterator.
Definition: for_each_selectors.h:253
bool operator()(_Op &__o, _It __i)
Functor execution.
Definition: for_each_selectors.h:59
bool operator()(_Op &__o, _It __i)
Functor execution.
Definition: for_each_selectors.h:170
__max_element_reduct(_Compare &__c)
Definition: for_each_selectors.h:326
Includes the original header files concerned with iterators except for stream iterators. This file is a GNU parallel extension to the Standard C++ Library.
std::transform() __selector, two input sequences variant.
Definition: for_each_selectors.h:116
_It operator()(_It __x, _It __y)
Definition: for_each_selectors.h:315
__replace_selector(const _Tp &__new_val)
Constructor.
Definition: for_each_selectors.h:140
std::count() selector.
Definition: for_each_selectors.h:180
bool operator()(_ValueType &__v, _It __i)
Functor execution.
Definition: for_each_selectors.h:91
_It operator()(_It __x, _It __y)
Definition: for_each_selectors.h:329
_It _M_finish_iterator
_Iterator on last element processed; needed for some algorithms (e. g. std::transform()).
Definition: for_each_selectors.h:47
bool operator()(_Op &__o, _It __i)
Functor execution.
Definition: for_each_selectors.h:123
const _Tp & __new_val
Value to replace with.
Definition: for_each_selectors.h:135
std::fill() selector.
Definition: for_each_selectors.h:84
bool operator()(_Op &__o, _It __i)
Definition: for_each_selectors.h:274
std::replace() selector.
Definition: for_each_selectors.h:132
std::accumulate() selector.
Definition: for_each_selectors.h:208
std::for_each() selector.
Definition: for_each_selectors.h:52
std::count_if () selector.
Definition: for_each_selectors.h:194
_Result operator()(const _Result &__x, const _Addend &__y)
Definition: for_each_selectors.h:344
_It operator()(_Op __o, _It __i)
Functor execution.
Definition: for_each_selectors.h:261
General reduction, using a binary operator.
Definition: for_each_selectors.h:335
std::iterator_traits< _It >::value_type operator()(_Op __o, _It __i)
Functor execution.
Definition: for_each_selectors.h:216
_BinOp & __binop
Definition: for_each_selectors.h:337
std::generate() selector.
Definition: for_each_selectors.h:68
std::transform() __selector, one input sequence variant.
Definition: for_each_selectors.h:100
Selector that returns the difference between two adjacent __elements.
Definition: for_each_selectors.h:269
Reduction function doing nothing.
Definition: for_each_selectors.h:298
bool operator()(_Op &__o, _It __i)
Functor execution.
Definition: for_each_selectors.h:107