Skip to content

Commit 03948a4

Browse files
committed
ranges::find, lower_bound, equal_range : 射影変換の例でコピーを抑止するよう修正
1 parent 0844fd3 commit 03948a4

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

reference/algorithm/ranges_equal_range.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ int main() {
218218
v,
219219
key,
220220
{},
221-
[](const X& x) { return x.name; }
221+
// x.nameがコピーされないよう戻り値型を明示的に指定
222+
[](const X& x) -> const std::string& { return x.name; }
222223
);
223224
std::cout << "[ラムダ式]" << std::endl;
224225
for (const X& x : result2) {

reference/algorithm/ranges_find.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ int main() {
140140
auto it = std::ranges::find(
141141
v,
142142
std::string("bbb"),
143-
[](const Item& x) { return x.name; }
143+
// コピーされないよう戻り値型を明示的に指定
144+
[](const Item& x) -> const std::string& { return x.name; }
144145
);
145146
if (it == v.end()) {
146147
std::cout << "not found" << std::endl;

reference/algorithm/ranges_lower_bound.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ int main() {
267267
v,
268268
key,
269269
{},
270-
[](const X& x) { return x.name; }
270+
// コピーされないよう戻り値型を明示的に指定
271+
[](const X& x) -> const std::string& { return x.name; }
271272
);
272273
if (it2 != v.end() && it2->name == key) {
273274
std::size_t pos = std::ranges::distance(v.begin(), it2);

0 commit comments

Comments
 (0)