Skip to content

Commit da5a5dc

Browse files
committed
いくつかのコード例のコンパイルエラーを修正
1 parent 699900b commit da5a5dc

File tree

19 files changed

+26
-28
lines changed

19 files changed

+26
-28
lines changed

reference/algorithm/ranges_count.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct Item {
145145
};
146146
147147
int main() {
148-
std::vector<Point> v = {
148+
std::vector<Item> v = {
149149
{1, "foo"},
150150
{3, "bar"},
151151
{5, "foo"},

reference/algorithm/ranges_find_end.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,20 @@ namespace std::ranges {
6666
#include <iostream>
6767
#include <vector>
6868
#include <list>
69+
#include <ranges>
6970
7071
int main() {
7172
std::vector<int> v = { 1,2,1,2,3 };
7273
std::list<int> ls = { 1,2 };
7374
7475
// 1,2 と連続している最後のシーケンスを探す
75-
subrange it = std::ranges::find_end(v, ls);
76+
std::ranges::subrange sr = std::ranges::find_end(v, ls);
7677
// v[2] の位置を指すイテレータが見つかる。
7778
// v[0] の位置を指すイテレータではない。
78-
if (it == v.end()) {
79+
if (sr.empty()) {
7980
std::cout << "not found" << std::endl;
8081
} else {
81-
std::cout << "found: index==" << std::distance(v.begin(), it) << std::endl;
82+
std::cout << "found: index==" << std::distance(v.begin(), sr.begin()) << std::endl;
8283
}
8384
}
8485
```

reference/algorithm/ranges_find_first_of.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main() {
6868
std::list ls = { 2,4,6,8 };
6969
7070
// 2,4,6,8 のどれかと一致する最初の要素を返す
71-
auto it = std::ranges::find_first_of(v, ls.begin(), ls.end());
71+
auto it = std::ranges::find_first_of(v, ls);
7272
if (it == v.end()) {
7373
std::cout << "not found" << std::endl;
7474
} else {
@@ -77,8 +77,6 @@ int main() {
7777
}
7878
```
7979
* std::ranges::find_first_of[color ff0000]
80-
* ls.begin()[link /reference/list/list/begin.md]
81-
* ls.end()[link /reference/list/list/end.md]
8280

8381
### 出力
8482
```

reference/algorithm/ranges_fold_right.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ return accum;
160160
#include <functional>
161161
#include <format>
162162
#include <vector>
163-
#include <iostream>
163+
#include <print>
164164
#include <concepts>
165165

166166
using namespace std::ranges;
@@ -206,7 +206,7 @@ int main() {
206206
#include <functional>
207207
#include <format>
208208
#include <vector>
209-
#include <iostream>
209+
#include <print>
210210
#include <concepts>
211211
212212
using namespace std::ranges;
@@ -253,7 +253,7 @@ init -> f -> e -> d -> c -> b -> a
253253
#include <functional>
254254
#include <format>
255255
#include <vector>
256-
#include <iostream>
256+
#include <print>
257257
#include <concepts>
258258

259259
using namespace std::ranges;

reference/algorithm/ranges_for_each.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ for_each_result {
7979
#include <algorithm>
8080

8181
int main() {
82-
constexpr std::array v = { 3, 1, 4 };
82+
std::array v = { 3, 1, 4 };
8383

8484
// vの全ての要素にラムダ式を適用する
8585
std::ranges::for_each(v, [](int x) { std::cout << x << std::endl; });

reference/algorithm/ranges_for_each_n.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void f(int& x)
6262

6363
int main()
6464
{
65-
constexpr std::array<int> v = {3, 1, 4, 5, 2};
65+
std::array v = {3, 1, 4, 5, 2};
6666

6767
// コンテナvの先頭3要素に、関数f()を適用する。
6868
// 関数f()は要素の変更を行う

reference/algorithm/ranges_transform.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,14 @@ int main() {
172172
std::vector<std::string> result;
173173

174174
// v1[n] の文字を v2[n] 回繰り返した文字列を返す
175-
std::ranges::transform(v1, v2, std::back_inserter(result), [](char a, int b) { return std::to_string(b, a); });
175+
std::ranges::transform(v1, v2, std::back_inserter(result), [](char a, int b) { return std::string(b, a); });
176176

177177
for (const std::string& s : result) {
178178
std::cout << s << std::endl;
179179
}
180180
}
181181
```
182182
* std::ranges::transform[color ff0000]
183-
* std::to_string[link /reference/string/to_string.md]
184183

185184
### 出力
186185
```

reference/algorithm/transform.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int main() {
136136

137137
// v1[n] の文字を v2[n] 回繰り返した文字列を返す
138138
std::transform(v1.begin(), v1.end(), v2.begin(), std::back_inserter(result),
139-
[](char a, int b) { return std::to_string(b, a); });
139+
[](char a, int b) { return std::string(b, a); });
140140

141141
std::for_each(result.begin(), result.end(),
142142
[](const std::string& s) { std::cout << s << std::endl; });
@@ -145,7 +145,6 @@ int main() {
145145
* std::transform[color ff0000]
146146
* result.begin()[link /reference/vector/vector/begin.md]
147147
* result.end()[link /reference/vector/vector/end.md]
148-
* std::to_string[link /reference/string/to_string.md]
149148

150149
### 出力
151150
```

reference/limits/numeric_limits/max_digits10.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static constexpr int max_digits10;
4040
#include <cmath>
4141
#include <sstream>
4242
#include <bitset>
43+
#include <cstring>
4344

4445
std::string make_float_string(float f, int digits) {
4546
std::stringstream s;

reference/memory/declare_no_pointers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace std {
5555
// GC負荷が大きい関数のダミー定義
5656
void some_operation_that_cause_gc() {}
5757
58-
int* ptr = nullptr;
58+
intptr_t* ptr = nullptr;
5959
6060
int main()
6161
{

0 commit comments

Comments
 (0)