avoid push_back in loops

Detected by clang-tidy.
This commit is contained in:
Danny Robson 2018-07-24 15:49:11 +10:00
parent cf800a35da
commit 79409eb6fe
2 changed files with 12 additions and 9 deletions

View File

@ -34,14 +34,12 @@ main (void)
{ {
util::job::queue q {std::thread::hardware_concurrency (), INNER}; util::job::queue q {std::thread::hardware_concurrency (), INNER};
std::vector<util::job::queue::cookie> cookies; std::vector<util::job::queue::cookie> cookies;
for (int j = 0; j < INNER; ++j) { std::generate_n (std::back_inserter (cookies), INNER, [&] () {
cookies.push_back ( return q.submit (
q.submit ( sleep_inc,
sleep_inc, std::ref (count)
std::ref (count)
)
); );
} });
} }
success = count == INNER && success; success = count == INNER && success;

View File

@ -60,8 +60,13 @@ main ()
}; };
std::vector<std::thread> workers; std::vector<std::thread> workers;
for (int i = 0; i < parallelism; ++i) std::generate_n (
workers.emplace_back (func, i); std::back_inserter (workers),
parallelism,
[&, i = 0] () mutable
{
return std::thread { func, i++ };
});
for (auto &t: workers) for (auto &t: workers)
t.join (); t.join ();