Skip to content

Commit be2a767

Browse files
authored
Merge pull request MicrosoftDocs#220 from tuncatunc/master
Uniform initialization is used.
2 parents 6b4ca24 + 3bff7b7 commit be2a767

7 files changed

+66
-66
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
vector<shared_ptr<Song>> v;
2-
3-
v.push_back(make_shared<Song>(L"Bob Dylan", L"The Times They Are A Changing"));
4-
v.push_back(make_shared<Song>(L"Aretha Franklin", L"Bridge Over Troubled Water"));
5-
v.push_back(make_shared<Song>(L"Thal�a", L"Entre El Mar y Una Estrella"));
1+
vector<shared_ptr<Song>> v {
2+
make_shared<Song>(L"Bob Dylan", L"The Times They Are A Changing"),
3+
make_shared<Song>(L"Aretha Franklin", L"Bridge Over Troubled Water"),
4+
make_shared<Song>(L"Thal�a", L"Entre El Mar y Una Estrella")
5+
};
66

77
vector<shared_ptr<Song>> v2;
88
remove_copy_if(v.begin(), v.end(), back_inserter(v2), [] (shared_ptr<Song> s)
@@ -13,4 +13,4 @@
1313
for (const auto& s : v2)
1414
{
1515
wcout << s->artist << L":" << s->title << endl;
16-
}
16+
}

docs/cpp/codesnippet/CPP/how-to-create-and-use-shared-ptr-instances_4.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
vector<shared_ptr<MediaAsset>> assets;
2-
3-
assets.push_back(shared_ptr<Song>(new Song(L"Himesh Reshammiya", L"Tera Surroor")));
4-
assets.push_back(shared_ptr<Song>(new Song(L"Penaz Masani", L"Tu Dil De De")));
5-
assets.push_back(shared_ptr<Photo>(new Photo(L"2011-04-06", L"Redmond, WA", L"Soccer field at Microsoft.")));
1+
vector<shared_ptr<MediaAsset>> assets {
2+
make_shared<Song>(L"Himesh Reshammiya", L"Tera Surroor"),
3+
make_shared<Song>(L"Penaz Masani", L"Tu Dil De De")),
4+
make_shared<Photo>(L"2011-04-06", L"Redmond, WA", L"Soccer field at Microsoft.")
5+
};
66

77
vector<shared_ptr<MediaAsset>> photos;
88

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
void SongVector()
22
{
33
vector<unique_ptr<Song>> songs;
4-
4+
55
// Create a few new unique_ptr<Song> instances
66
// 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"));
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"));
1010
songs.push_back(make_unique<Song>(L"Ayumi Hamasaki", L"Poker Face"));
1111

1212
// Pass by const reference when possible to avoid copying.

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)