Utilities
Utilities header only library
ExtOMP.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_EXT_OMP_H
7 #define UTILS_EXT_OMP_H
8 
9 #include <functional>
10 
11 
12 
14 namespace omp_ext
15 {
16 
21  template<class C, class F>
22  [[nodiscard]]
23  auto Transformed(const C &container, F Function)
24  {
25  using RT = std::vector<decltype(Function(std::declval<typename C::value_type>()))>;
26 
27  const size_t size = container.size();
28  RT result(size);
29 
30  #pragma omp parallel for
31  for (int i = 0; i < static_cast<int>(size); ++i)
32  {
33  result[i] = Function(container[i]);
34  }
35 
36  return result;
37  }
38 }
39 
40 #endif /* !UTILS_EXT_OMP_H */
auto Transformed(const C &container, F Function)
Transforms a container in parallel by passing each element through a callable object (function/functo...
Definition: ExtOMP.h:23
Extensions to OpenMP.
Definition: ExtOMP.h:14