Skip to content

Commit 736269d

Browse files
committed
Use uniform initializer where it's reasonable.
1 parent 7e249e9 commit 736269d

5 files changed

+57
-57
lines changed

docs/cpp/codesnippet/CPP/how-to-create-and-use-unique-ptr-instances_2.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
void SongVector()
22
{
3-
vector<unique_ptr<Song>> songs;
4-
53
// Create a few new unique_ptr<Song> instances
64
// and add them to vector using implicit move semantics.
7-
songs.push_back(make_unique<Song>(L"B'z", L"Juice"));
8-
songs.push_back(make_unique<Song>(L"Namie Amuro", L"Funky Town"));
9-
songs.push_back(make_unique<Song>(L"Kome Kome Club", L"Kimi ga Iru Dake de"));
10-
songs.push_back(make_unique<Song>(L"Ayumi Hamasaki", L"Poker Face"));
5+
vector<unique_ptr<Song>> songs {
6+
make_unique<Song>(L"B'z", L"Juice"),
7+
make_unique<Song>(L"Namie Amuro", L"Funky Town"),
8+
make_unique<Song>(L"Kome Kome Club", L"Kimi ga Iru Dake de"),
9+
make_unique<Song>(L"Ayumi Hamasaki", L"Poker Face")
10+
};
1111

1212
// Pass by const reference when possible to avoid copying.
1313
for (const auto& song : songs)

docs/cpp/codesnippet/CPP/how-to-create-and-use-weak-ptr-instances_1.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ class Controller
4444

4545
void RunTest()
4646
{
47-
vector<shared_ptr<Controller>> v;
48-
49-
v.push_back(shared_ptr<Controller>(new Controller(0)));
50-
v.push_back(shared_ptr<Controller>(new Controller(1)));
51-
v.push_back(shared_ptr<Controller>(new Controller(2)));
52-
v.push_back(shared_ptr<Controller>(new Controller(3)));
53-
v.push_back(shared_ptr<Controller>(new Controller(4)));
47+
vector<shared_ptr<Controller>> v {
48+
make_shared<Controller>(0),
49+
make_shared<Controller>(1),
50+
make_shared<Controller>(2),
51+
make_shared<Controller>(3),
52+
make_shared<Controller>(4),
53+
};
5454

5555
// Each controller depends on all others not being deleted.
5656
// Give each controller a pointer to all the others.

docs/parallel/concrt/codesnippet/CPP/how-to-perform-map-and-reduce-operations-in-parallel_1.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ struct ReduceFunc : binary_function<unordered_map<wstring, size_t>,
4646
int wmain()
4747
{
4848
// File 1
49-
vector<wstring> v1;
50-
v1.push_back(L"word1"); //1
51-
v1.push_back(L"word1"); //2
52-
v1.push_back(L"word2");
53-
v1.push_back(L"word3");
54-
v1.push_back(L"word4");
49+
vector<wstring> v1 {
50+
L"word1", // 1
51+
L"word1", // 1
52+
L"word2",
53+
L"word3",
54+
L"word4"
55+
};
5556

5657
// File 2
57-
vector<wstring> v2;
58-
v2.push_back(L"word5");
59-
v2.push_back(L"word6");
60-
v2.push_back(L"word7");
61-
v2.push_back(L"word8");
62-
v2.push_back(L"word1"); //3
58+
vector<wstring> v2 {
59+
L"word5",
60+
L"word6",
61+
L"word7",
62+
L"word8",
63+
L"word1" // 3
64+
};
6365

64-
vector<vector<wstring>> v;
65-
v.push_back(v1);
66-
v.push_back(v2);
66+
vector<vector<wstring>> v { v1, v2 };
6767

6868
vector<unordered_map<wstring, size_t>> map(v.size());
6969

docs/parallel/concrt/codesnippet/CPP/how-to-perform-map-and-reduce-operations-in-parallel_2.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// File 1
2-
vector<wstring> v1;
3-
v1.push_back(L"word1"); //1
4-
v1.push_back(L"word1"); //2
5-
v1.push_back(L"word2");
6-
v1.push_back(L"word3");
7-
v1.push_back(L"word4");
2+
vector<wstring> v1 {
3+
L"word1", // 1
4+
L"word1", // 2
5+
L"word2",
6+
L"word3",
7+
L"word4",
8+
};
89

910
// File 2
10-
vector<wstring> v2;
11-
v2.push_back(L"word5");
12-
v2.push_back(L"word6");
13-
v2.push_back(L"word7");
14-
v2.push_back(L"word8");
15-
v2.push_back(L"word1"); //3
11+
vector<wstring> v2 {
12+
L"word5",
13+
L"word6",
14+
L"word7",
15+
L"word8",
16+
L"word1", // 3
17+
};
1618

17-
vector<vector<wstring>> v;
18-
v.push_back(v1);
19-
v.push_back(v2);
19+
vector<vector<wstring>> v { v1, v2 };
2020

2121
concurrent_unordered_map<wstring, size_t> result;
2222
for_each(begin(v), end(v), [&result](const vector<wstring>& words) {

docs/parallel/concrt/codesnippet/CPP/parallel-algorithms_6.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
// compile with: /EHsc
33
#include <ppl.h>
44
#include <iostream>
5-
#include <string>
5+
#include <string>
66
#include <vector>
77

88
using namespace concurrency;
99
using namespace std;
1010

1111
int wmain()
1212
{
13-
// Create a vector of strings.
14-
vector<wstring> words;
15-
words.push_back(L"Lorem ");
16-
words.push_back(L"ipsum ");
17-
words.push_back(L"dolor ");
18-
words.push_back(L"sit ");
19-
words.push_back(L"amet, ");
20-
words.push_back(L"consectetur ");
21-
words.push_back(L"adipiscing ");
22-
words.push_back(L"elit.");
23-
24-
// Reduce the vector to one string in parallel.
25-
wcout << parallel_reduce(begin(words), end(words), wstring()) << endl;
13+
// Create a vector of strings.
14+
vector<wstring> words{
15+
L"Lorem ",
16+
L"ipsum ",
17+
L"dolor ",
18+
L"sit ",
19+
L"amet, ",
20+
L"consectetur ",
21+
L"adipiscing ",
22+
L"elit."};
23+
24+
// Reduce the vector to one string in parallel.
25+
wcout << parallel_reduce(begin(words), end(words), wstring()) << endl;
2626
}
2727

2828
/* Output:

0 commit comments

Comments
 (0)