Skip to content

Instantly share code, notes, and snippets.

@arnabanimesh
Last active January 1, 2025 07:41
Show Gist options
  • Save arnabanimesh/5a4785ef6d571294d6c649117d7a7dfb to your computer and use it in GitHub Desktop.
Save arnabanimesh/5a4785ef6d571294d6c649117d7a7dfb to your computer and use it in GitHub Desktop.
#include <numeric>
#include <string>
#include <ranges>
#include <execution>
#include <iterator>
#include <vector>
struct Output
{
int32_t serial;
std::string name;
int32_t count;
};
int main()
{
std::vector<int32_t> vec_iter = {0, 1};
std::vector<Output> output_list(vec_iter.size());
// mutex guard is not required as each element in vec_iter will be unique,
// and the output_list is not std::vector<bool>
std::for_each(std::execution::par, vec_iter.begin(), vec_iter.end(), [&](int32_t elem)
{ output_list[elem] = {1, "A", 1000}; });
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment