Skip to content

Commit 68f99d8

Browse files
committed
Use emplace_back() and for(a:b) loop.
1 parent b168ca0 commit 68f99d8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

example.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ int main()
1111
std::vector< std::future<int> > results;
1212

1313
for(int i = 0; i < 8; ++i) {
14-
results.push_back(
14+
results.emplace_back(
1515
pool.enqueue([i] {
1616
std::cout << "hello " << i << std::endl;
1717
std::this_thread::sleep_for(std::chrono::seconds(1));
1818
std::cout << "world " << i << std::endl;
1919
return i*i;
2020
})
2121
);
22-
}
23-
24-
for(size_t i = 0;i<results.size();++i)
25-
std::cout << results[i].get() << ' ';
22+
}
23+
24+
for(auto && result: results)
25+
std::cout << result.get() << ' ';
2626
std::cout << std::endl;
2727

2828
return 0;

0 commit comments

Comments
 (0)