Advertisement
ANevsky

Untitled

Apr 30th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. template <typename Container, typename Predicate>
  2. vector<typename Container::value_type> CopyIfUnordered(const Container& container, Predicate predicate) {
  3.     vector<typename Container::value_type> result(container.size());
  4.     atomic<int> size = 0;
  5.     for_each(
  6.         execution::par,
  7.         container.begin(), container.end(),
  8.         [&](const auto& value) {
  9.             if (predicate(value)) {
  10.                 typename Container::value_type* destination;
  11.                 {
  12.                     destination = &result[size++];
  13.                 }
  14.                 *destination = value;
  15.             }
  16.         }
  17.     );
  18.     result.resize(size);
  19.     return result;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement