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};
std::vector<util::job::queue::cookie> cookies;
for (int j = 0; j < INNER; ++j) {
cookies.push_back (
q.submit (
sleep_inc,
std::ref (count)
)
std::generate_n (std::back_inserter (cookies), INNER, [&] () {
return q.submit (
sleep_inc,
std::ref (count)
);
}
});
}
success = count == INNER && success;

View File

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