Skip to content

Instantly share code, notes, and snippets.

@brycelelbach
Created June 30, 2021 19:59
Show Gist options
  • Save brycelelbach/e66c7d7612cefba2ba86bfef8ce30a62 to your computer and use it in GitHub Desktop.
Save brycelelbach/e66c7d7612cefba2ba86bfef8ce30a62 to your computer and use it in GitHub Desktop.
std::vector v = ...;
auto min = std::ranges::min_element(v);
std::ranges::for_each(v, [&] (auto& e) { e /= min; });
std::vector v = ...;
auto min = std::ranges::min_element(v);
std::ranges::transform(v, v.begin(), [&] (auto e) { return e / min; });
std::vector v = ...;
auto min = std::ranges::min_element(v);
for (auto& e : v) e /= min;
std::vector v = ...;
auto min = std::ranges::min_element(v);
for (std::size_t i = 0; i < v.size(); ++i) e[i] /= min;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment