|
2 | 2 | <feed xmlns="http://www.w3.org/2005/Atom"> |
3 | 3 | <title>cpprefjp - C++日本語リファレンス</title> |
4 | 4 | <link href="https://cpprefjp.github.io" /> |
5 | | - <updated>2025-05-27T08:26:55.053411</updated> |
6 | | - <id>8255da7b-651d-464d-9372-382d2be045a9</id> |
| 5 | + <updated>2025-05-27T09:03:12.492214</updated> |
| 6 | + <id>f4d807f5-8a4f-4286-b166-6c53f2adab8f</id> |
7 | 7 |
|
8 | 8 |
|
| 9 | + <entry> |
| 10 | + <title>fold_left -- fold_left, fold_right : 箇条書きの表示崩れを修正</title> |
| 11 | + <link href="https://cpprefjp.github.io/reference/algorithm/ranges_fold_left.html"/> |
| 12 | + <id>9094beb997b31879c2fe78a6249d4cddc5163ba6:reference/algorithm/ranges_fold_left.md</id> |
| 13 | + <updated>2025-05-27T17:59:26+09:00</updated> |
| 14 | + |
| 15 | + <summary type="html"><pre><code>diff --git a/reference/algorithm/ranges_fold_left.md b/reference/algorithm/ranges_fold_left.md |
| 16 | +index 8c7651f38..cd35caa38 100644 |
| 17 | +--- a/reference/algorithm/ranges_fold_left.md |
| 18 | ++++ b/reference/algorithm/ranges_fold_left.md |
| 19 | +@@ -152,6 +152,7 @@ concept indirectly-binary-left-foldable = |
| 20 | + |
| 21 | + - すなわち、指定した二項演算を初期値とイテレータによって`f(std::move(init), *first)`のように呼び出した時の戻り値型がこの関数の戻り値型となる。 |
| 22 | + - また、この型`U`は`fold_left`の処理内部で積算値の型として使用されるものでもあり、`f`は`init`の代わりに`U`の右辺値も受け取れる必要がある。二項演算の呼び出しにおいては、第一引数に初期値もしくは積算値が渡され、第二引数にイテレータの間接参照結果が直接渡される。そして、二項演算の適用結果は積算値を保存する変数に直接代入される(つまり、結果を次のステップに引き継ぎたい場合は積算処理も二項演算内で行う必要がある)。詳細は下の実装例を参照。 |
| 23 | ++ |
| 24 | + - (1), (2) : |
| 25 | + - C++26 : 引数として波カッコ初期化`{}`を受け付ける |
| 26 | + ```cpp |
| 27 | +</code></pre></summary> |
| 28 | + |
| 29 | + <author> |
| 30 | + <name>Akira Takahashi</name> |
| 31 | + |
| 32 | + </author> |
| 33 | + </entry> |
| 34 | + |
| 35 | + <entry> |
| 36 | + <title>fold_right -- fold_left, fold_right : 箇条書きの表示崩れを修正</title> |
| 37 | + <link href="https://cpprefjp.github.io/reference/algorithm/ranges_fold_right.html"/> |
| 38 | + <id>9094beb997b31879c2fe78a6249d4cddc5163ba6:reference/algorithm/ranges_fold_right.md</id> |
| 39 | + <updated>2025-05-27T17:59:26+09:00</updated> |
| 40 | + |
| 41 | + <summary type="html"><pre><code>diff --git a/reference/algorithm/ranges_fold_right.md b/reference/algorithm/ranges_fold_right.md |
| 42 | +index 2c418690b..89531d1fd 100644 |
| 43 | +--- a/reference/algorithm/ranges_fold_right.md |
| 44 | ++++ b/reference/algorithm/ranges_fold_right.md |
| 45 | +@@ -149,6 +149,7 @@ return accum; |
| 46 | + |
| 47 | + - すなわち、指定した二項演算をイテレータと初期値によって`f(*first, std::move(init))`のように呼び出した時の戻り値型がこの関数の戻り値型となる。 |
| 48 | + - また、この型`U`は`fold_right`の処理内部で積算値の型として使用されるものでもあり、`f`は`init`の代わりに`U`の右辺値も受け取れる必要がある。二項演算の呼び出しにおいては、第一引数にイテレータの間接参照結果が直接渡され、第二引数に初期値もしくは積算値が渡される。そして、二項演算の適用結果は積算値を保存する変数に直接代入される(つまり、結果を次のステップに引き継ぎたい場合は積算処理も二項演算内で行う必要がある)。詳細は下の実装例を参照。 |
| 49 | ++ |
| 50 | + - (1), (2) : |
| 51 | + - C++26 : 引数として波カッコ初期化`{}`を受け付ける |
| 52 | + ```cpp |
| 53 | +</code></pre></summary> |
| 54 | + |
| 55 | + <author> |
| 56 | + <name>Akira Takahashi</name> |
| 57 | + |
| 58 | + </author> |
| 59 | + </entry> |
| 60 | + |
9 | 61 | <entry> |
10 | 62 | <title>count -- ranges::count, equal_range, lower_bound : 射影変換の例を追加</title> |
11 | 63 | <link href="https://cpprefjp.github.io/reference/algorithm/ranges_count.html"/> |
@@ -1118,286 +1170,6 @@ index 96a13edc2..2c418690b 100644 |
1118 | 1170 | - [プログラミングHaskellのfoldr, foldlの説明が秀逸だった件 - あと味](https://taiju.hatenablog.com/entry/20130202/1359773888) |
1119 | 1171 | +- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html) |
1120 | 1172 | + - C++26で波カッコ初期化 (リスト初期化) に対応した |
1121 | | -</code></pre></summary> |
1122 | | - |
1123 | | - <author> |
1124 | | - <name>Akira Takahashi</name> |
1125 | | - |
1126 | | - </author> |
1127 | | - </entry> |
1128 | | - |
1129 | | - <entry> |
1130 | | - <title>binary_search -- binary_search : C++26波カッコ初期化に対応 #1311</title> |
1131 | | - <link href="https://cpprefjp.github.io/reference/algorithm/binary_search.html"/> |
1132 | | - <id>93b8c47923f9c1090573b00a071cad863607d0a1:reference/algorithm/binary_search.md</id> |
1133 | | - <updated>2025-05-27T15:06:45+09:00</updated> |
1134 | | - |
1135 | | - <summary type="html"><pre><code>diff --git a/reference/algorithm/binary_search.md b/reference/algorithm/binary_search.md |
1136 | | -index 342f67c3d..a1c10635e 100644 |
1137 | | ---- a/reference/algorithm/binary_search.md |
1138 | | -+++ b/reference/algorithm/binary_search.md |
1139 | | -@@ -5,27 +5,35 @@ |
1140 | | - |
1141 | | - ```cpp |
1142 | | - namespace std { |
1143 | | -- template &lt;class ForwardIterator, class T&gt; |
1144 | | -- bool binary_search(ForwardIterator first, |
1145 | | -- ForwardIterator last, |
1146 | | -- const T&amp; value); // (1) C++03 |
1147 | | -- |
1148 | | -- template &lt;class ForwardIterator, class T&gt; |
1149 | | -- constexpr bool binary_search(ForwardIterator first, |
1150 | | -- ForwardIterator last, |
1151 | | -- const T&amp; value); // (1) C++20 |
1152 | | -- |
1153 | | -- template &lt;class ForwardIterator, class T, class Compare&gt; |
1154 | | -- bool binary_search(ForwardIterator first, |
1155 | | -- ForwardIterator last, |
1156 | | -- const T&amp; value, |
1157 | | -- Compare comp); // (2) C++03 |
1158 | | -- |
1159 | | -- template &lt;class ForwardIterator, class T, class Compare&gt; |
1160 | | -- constexpr bool binary_search(ForwardIterator first, |
1161 | | -- ForwardIterator last, |
1162 | | -- const T&amp; value, |
1163 | | -- Compare comp); // (2) C++20 |
1164 | | -+ template &lt;class ForwardIterator, |
1165 | | -+ class T&gt; |
1166 | | -+ bool |
1167 | | -+ binary_search(ForwardIterator first, |
1168 | | -+ ForwardIterator last, |
1169 | | -+ const T&amp; value); // (1) C++03 |
1170 | | -+ template &lt;class ForwardIterator, |
1171 | | -+ class T&gt; |
1172 | | -+ constexpr bool |
1173 | | -+ binary_search(ForwardIterator first, |
1174 | | -+ ForwardIterator last, |
1175 | | -+ const T&amp; value); // (1) C++20 |
1176 | | -+ |
1177 | | -+ template &lt;class ForwardIterator, |
1178 | | -+ class T, |
1179 | | -+ class Compare&gt; |
1180 | | -+ bool |
1181 | | -+ binary_search(ForwardIterator first, |
1182 | | -+ ForwardIterator last, |
1183 | | -+ const T&amp; value, |
1184 | | -+ Compare comp); // (2) C++03 |
1185 | | -+ template &lt;class ForwardIterator, |
1186 | | -+ class T, |
1187 | | -+ class Compare&gt; |
1188 | | -+ constexpr bool |
1189 | | -+ binary_search(ForwardIterator first, |
1190 | | -+ ForwardIterator last, |
1191 | | -+ const T&amp; value, |
1192 | | -+ Compare comp); // (2) C++20 |
1193 | | - } |
1194 | | - ``` |
1195 | | - |
1196 | | -@@ -49,9 +57,16 @@ namespace std { |
1197 | | - |
1198 | | - ## 備考 |
1199 | | - - `comp` は 2 引数の関数オブジェクトで、1 番目の引数が 2 番目の引数「より小さい」場合に `true` を、そうでない場合に `false` を返すものとして扱われる。 |
1200 | | -+- (1), (2) : |
1201 | | -+ - C++26 : 引数として波カッコ初期化`{}`を受け付ける |
1202 | | -+ ```cpp |
1203 | | -+ std::vector&lt;T&gt; v; |
1204 | | -+ bool found = std::binary_search(v.begin(), v.end(), {a, b}); |
1205 | | -+ ``` |
1206 | | - |
1207 | | - |
1208 | | - ## 例 |
1209 | | -+### 基本的な使い方 |
1210 | | - ```cpp example |
1211 | | - #include &lt;iostream&gt; |
1212 | | - #include &lt;vector&gt; |
1213 | | -@@ -74,6 +89,44 @@ int main() |
1214 | | - ``` |
1215 | | - * std::binary_search[color ff0000] |
1216 | | - |
1217 | | -+#### 出力 |
1218 | | -+``` |
1219 | | -+found |
1220 | | -+``` |
1221 | | -+ |
1222 | | -+### 波カッコ初期化を入力として使用する (C++26) |
1223 | | -+```cpp example |
1224 | | -+#include &lt;algorithm&gt; |
1225 | | -+#include &lt;iostream&gt; |
1226 | | -+#include &lt;vector&gt; |
1227 | | -+ |
1228 | | -+struct Point { |
1229 | | -+ int x; |
1230 | | -+ int y; |
1231 | | -+ |
1232 | | -+ bool operator==(const Point&amp; other) const = default; |
1233 | | -+ auto operator&lt;=&gt;(const Point&amp; other) const = default; |
1234 | | -+}; |
1235 | | -+ |
1236 | | -+int main() { |
1237 | | -+ std::vector&lt;Point&gt; v = { |
1238 | | -+ {1, 2}, |
1239 | | -+ {3, 4}, |
1240 | | -+ {5, 6}, |
1241 | | -+ }; |
1242 | | -+ |
1243 | | -+ // 値{3, 4}を二分検索 |
1244 | | -+ bool found = std::binary_search(v.begin(), v.end(), {3, 4}); |
1245 | | -+ if (found) { |
1246 | | -+ std::cout &lt;&lt; &#34;found&#34; &lt;&lt; std::endl; |
1247 | | -+ } |
1248 | | -+ else { |
1249 | | -+ std::cout &lt;&lt; &#34;not found&#34; &lt;&lt; std::endl; |
1250 | | -+ } |
1251 | | -+} |
1252 | | -+``` |
1253 | | -+* std::binary_search[color ff0000] |
1254 | | -+ |
1255 | | - ### 出力 |
1256 | | - ``` |
1257 | | - found |
1258 | | -@@ -114,3 +167,5 @@ bool binary_search(ForwardIterator first, ForwardIterator last, |
1259 | | - - [LWG Issue 787. complexity of `binary_search`](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#787) |
1260 | | - - C++03までの計算量が間違っていたので、C++11で修正。 |
1261 | | - - [P0202R3 Add Constexpr Modifiers to Functions in `&lt;algorithm&gt;` and `&lt;utility&gt;` Headers](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html) |
1262 | | -+- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html) |
1263 | | -+ - C++26で波カッコ初期化 (リスト初期化) に対応した |
1264 | | -</code></pre></summary> |
1265 | | - |
1266 | | - <author> |
1267 | | - <name>Akira Takahashi</name> |
1268 | | - |
1269 | | - </author> |
1270 | | - </entry> |
1271 | | - |
1272 | | - <entry> |
1273 | | - <title>binary_search -- binary_search : C++26波カッコ初期化に対応 #1311</title> |
1274 | | - <link href="https://cpprefjp.github.io/reference/algorithm/ranges_binary_search.html"/> |
1275 | | - <id>93b8c47923f9c1090573b00a071cad863607d0a1:reference/algorithm/ranges_binary_search.md</id> |
1276 | | - <updated>2025-05-27T15:06:45+09:00</updated> |
1277 | | - |
1278 | | - <summary type="html"><pre><code>diff --git a/reference/algorithm/ranges_binary_search.md b/reference/algorithm/ranges_binary_search.md |
1279 | | -index 54df91313..7c950f41a 100644 |
1280 | | ---- a/reference/algorithm/ranges_binary_search.md |
1281 | | -+++ b/reference/algorithm/ranges_binary_search.md |
1282 | | -@@ -10,13 +10,30 @@ namespace std::ranges { |
1283 | | - sentinel_for&lt;I&gt; S, |
1284 | | - class T, |
1285 | | - class Proj = identity, |
1286 | | -- indirect_strict_weak_order&lt;const T*, projected&lt;I, Proj&gt;&gt; Comp = ranges::less&gt; |
1287 | | -+ indirect_strict_weak_order&lt; |
1288 | | -+ const T*, |
1289 | | -+ projected&lt;I, Proj&gt; |
1290 | | -+ &gt; Comp = ranges::less&gt; |
1291 | | - constexpr bool |
1292 | | - binary_search(I first, |
1293 | | - S last, |
1294 | | - const T&amp; value, |
1295 | | - Comp comp = {}, |
1296 | | - Proj proj = {}); // (1) C++20 |
1297 | | -+ template &lt;forward_iterator I, |
1298 | | -+ sentinel_for&lt;I&gt; S, |
1299 | | -+ class Proj = identity, |
1300 | | -+ class T = projected_value_t&lt;I, Proj&gt;, |
1301 | | -+ indirect_strict_weak_order&lt; |
1302 | | -+ const T*, |
1303 | | -+ projected&lt;I, Proj&gt; |
1304 | | -+ &gt; Comp = ranges::less&gt; |
1305 | | -+ constexpr bool |
1306 | | -+ binary_search(I first, |
1307 | | -+ S last, |
1308 | | -+ const T&amp; value, |
1309 | | -+ Comp comp = {}, |
1310 | | -+ Proj proj = {}); // (1) C++26 |
1311 | | - |
1312 | | - template &lt;forward_range R, |
1313 | | - class T, |
1314 | | -@@ -30,6 +47,18 @@ namespace std::ranges { |
1315 | | - const T&amp; value, |
1316 | | - Comp comp = {}, |
1317 | | - Proj proj = {}); // (2) C++20 |
1318 | | -+ template &lt;forward_range R, |
1319 | | -+ class Proj = identity, |
1320 | | -+ class T = projected_value_t&lt;iterator_t&lt;R&gt;, Proj&gt;, |
1321 | | -+ indirect_strict_weak_order&lt; |
1322 | | -+ const T*, |
1323 | | -+ projected&lt;iterator_t&lt;R&gt;, Proj&gt; |
1324 | | -+ &gt; Comp = ranges::less&gt; |
1325 | | -+ constexpr bool |
1326 | | -+ binary_search(R&amp;&amp; r, |
1327 | | -+ const T&amp; value, |
1328 | | -+ Comp comp = {}, |
1329 | | -+ Proj proj = {}); // (2) C++26 |
1330 | | - } |
1331 | | - ``` |
1332 | | - * forward_iterator[link /reference/iterator/forward_iterator.md] |
1333 | | -@@ -65,9 +94,15 @@ namespace std::ranges { |
1334 | | - |
1335 | | - ## 備考 |
1336 | | - - `comp` は 2 引数の関数オブジェクトで、1 番目の引数が 2 番目の引数「より小さい」場合に `true` を、そうでない場合に `false` を返すものとして扱われる。 |
1337 | | -- |
1338 | | -+- (1), (2) : |
1339 | | -+ - C++26 : 引数として波カッコ初期化`{}`を受け付ける |
1340 | | -+ ```cpp |
1341 | | -+ std::vector&lt;T&gt; v; |
1342 | | -+ bool found = std::ranges::binary_search(v, {a, b}); |
1343 | | -+ ``` |
1344 | | - |
1345 | | - ## 例 |
1346 | | -+### 基本的な使い方 |
1347 | | - ```cpp example |
1348 | | - #include &lt;iostream&gt; |
1349 | | - #include &lt;vector&gt; |
1350 | | -@@ -90,6 +125,44 @@ int main() |
1351 | | - ``` |
1352 | | - * std::ranges::binary_search[color ff0000] |
1353 | | - |
1354 | | -+#### 出力 |
1355 | | -+``` |
1356 | | -+found |
1357 | | -+``` |
1358 | | -+ |
1359 | | -+### 波カッコ初期化を入力として使用する (C++26) |
1360 | | -+```cpp example |
1361 | | -+#include &lt;algorithm&gt; |
1362 | | -+#include &lt;iostream&gt; |
1363 | | -+#include &lt;vector&gt; |
1364 | | -+ |
1365 | | -+struct Point { |
1366 | | -+ int x; |
1367 | | -+ int y; |
1368 | | -+ |
1369 | | -+ bool operator==(const Point&amp; other) const = default; |
1370 | | -+ auto operator&lt;=&gt;(const Point&amp; other) const = default; |
1371 | | -+}; |
1372 | | -+ |
1373 | | -+int main() { |
1374 | | -+ std::vector&lt;Point&gt; v = { |
1375 | | -+ {1, 2}, |
1376 | | -+ {3, 4}, |
1377 | | -+ {5, 6}, |
1378 | | -+ }; |
1379 | | -+ |
1380 | | -+ // 値{3, 4}を二分検索 |
1381 | | -+ bool found = std::ranges::binary_search(v, {3, 4}); |
1382 | | -+ if (found) { |
1383 | | -+ std::cout &lt;&lt; &#34;found&#34; &lt;&lt; std::endl; |
1384 | | -+ } |
1385 | | -+ else { |
1386 | | -+ std::cout &lt;&lt; &#34;not found&#34; &lt;&lt; std::endl; |
1387 | | -+ } |
1388 | | -+} |
1389 | | -+``` |
1390 | | -+* std::ranges::binary_search[color ff0000] |
1391 | | -+ |
1392 | | - ### 出力 |
1393 | | - ``` |
1394 | | - found |
1395 | | -@@ -107,3 +180,5 @@ found |
1396 | | - |
1397 | | - ## 参照 |
1398 | | - - [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms) |
1399 | | -+- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html) |
1400 | | -+ - C++26で波カッコ初期化 (リスト初期化) に対応した |
1401 | 1173 | </code></pre></summary> |
1402 | 1174 |
|
1403 | 1175 | <author> |
|
0 commit comments