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-07-08T13:36:47.897782 </updated >
6
- <id >4ea53472-a487-4a5f-a3fd-53f09d8bc0ed </id >
5
+ <updated >2025-07-08T13:53:28.636802 </updated >
6
+ <id >a6a9c0ba-bfd8-4bca-8623-1a36903edca2 </id >
7
7
8
8
9
+ <entry >
10
+ <title >erase -- deque::erase(): イテレータと参照の無効化について微修正</title >
11
+ <link href =" https://cpprefjp.github.io/reference/deque/deque/erase.html" />
12
+ <id >b7d05c0d904106c98c194f1a9cac27ad71253e8e:reference/deque/deque/erase.md</id >
13
+ <updated >2025-07-08T22:49:10+09:00</updated >
14
+
15
+ <summary type =" html" >< pre>< code> diff --git a/reference/deque/deque/erase.md b/reference/deque/deque/erase.md
16
+ index 303d0facb..8d3174777 100644
17
+ --- a/reference/deque/deque/erase.md
18
+ +++ b/reference/deque/deque/erase.md
19
+ @@ -20,7 +20,7 @@ iterator erase(const_iterator first, const_iterator last); // (2) C++11
20
+ - (1) : `position`が指す要素を削除する。
21
+ - (2) : イテレータ範囲`[first, last)`の要素を削除する。
22
+
23
+ -もし削除がシーケンスの先頭または末尾から行われた場合、削除された要素へのイテレータと参照は無効化される。もし削除が中間位置から行われた場合、全てのイテレータと削除は無効化される。
24
+ +もし削除がシーケンスの先頭または末尾から行われた場合、削除された要素へのイテレータと参照だけが無効化される(そのほかの要素への参照/イテレータは有効であり続ける)。一方、削除が中間位置から行われた場合は全てのイテレータと参照が無効化される。
25
+
26
+
27
+ ## 戻り値
28
+ < /code>< /pre> </summary >
29
+
30
+ <author >
31
+ <name >onihusube</name >
32
+
33
+ </author >
34
+ </entry >
35
+
9
36
<entry >
10
37
<title >derived_from -- improve std::derived_from</title >
11
38
<link href =" https://cpprefjp.github.io/reference/concepts/derived_from.html" />
@@ -474,103 +501,4 @@ index 8d785c808..5ebd2ff78 100644
474
501
</author >
475
502
</entry >
476
503
477
- <entry >
478
- <title >realloc -- new page `cstdlib/realloc`</title >
479
- <link href =" https://cpprefjp.github.io/reference/cstdlib/realloc.html" />
480
- <id >f52245801379796df95cd3829341795846bfd15b:reference/cstdlib/realloc.md</id >
481
- <updated >2025-07-08T19:57:31+09:00</updated >
482
-
483
- <summary type =" html" >< pre>< code> diff --git a/reference/cstdlib/realloc.md b/reference/cstdlib/realloc.md
484
- new file mode 100644
485
- index 000000000..3b807a5b8
486
- --- /dev/null
487
- +++ b/reference/cstdlib/realloc.md
488
- @@ -0,0 +1,79 @@
489
- +# realloc
490
- +* cstdlib[meta header]
491
- +* std[meta namespace]
492
- +* function[meta id-type]
493
- +
494
- +```cpp
495
- +namespace std {
496
- + void* realloc(void* ptr, size_t new_size);
497
- +}
498
- +```
499
- +
500
- +## 概要
501
- +確保済みの領域`ptr`を`new_size`に再確保する。
502
- +
503
- +`ptr`は、`calloc`、`malloc`、`realloc`で事前に確保され、なおかつ`free`で解放されていないメモリである必要がある。
504
- +
505
- +それ以外のメモリの場合、動作は未定義である。
506
- +
507
- +`ptr`に`nullptr`を渡した場合、`malloc(new_size)`として動作する。
508
- +
509
- +## 効果
510
- +メモリの確保は次のいずれかの方法で行われる。
511
- +
512
- + - 既存のメモリを拡張、縮小する。
513
- +
514
- + 縮小した場合、再確保されたメモリのサイズまでの領域の内容が保持される。
515
- +
516
- + 拡張した場合、新しい領域の内容は未定義である。
517
- +
518
- + - 新しいサイズの領域を確保、割り当てする。その後、新しいサイズと古いサイズのいずれか小さい方のサイズに等しいメモリ領域をコピーし、古いブロックを解放する。
519
- +
520
- + - メモリが不足している場合、`nullpte`が返される。
521
- +
522
- +## 備考
523
- +`new_size`が0の場合の動作は定義されていない。
524
- +
525
- +## 戻り値
526
- +再確保できた場合、その領域の先頭のポインタを返す。
527
- +
528
- +なお、その領域はメモリリークを避けるため、`free`、`realloc`で解放する必要がある。
529
- +
530
- +失敗した場合、`nullptr`を返す。もとのポインタは有効なままで、解放する必要がある。
531
- +
532
- +## 例
533
- +```cpp example
534
- +#include & lt;cstdlib& gt;
535
- +#include & lt;iostream& gt;
536
- +
537
- +int main() {
538
- + // 初期サイズでメモリを確保
539
- + int* p = static_cast& lt;int*& gt;(std::malloc(5 * sizeof(int)));
540
- + if (!p) return 1;
541
- + for (int i = 0; i & lt; 5; ++i) {
542
- + p[i] = i;
543
- + }
544
- + // サイズを再確保(拡張)
545
- + int* q = static_cast& lt;int*& gt;(std::realloc(p, 10 * sizeof(int)));
546
- + if (!q) {
547
- + std::free(p);
548
- + std::cerr & lt;& lt; & #34;realloc failed& #34; & lt;& lt; std::endl;
549
- + return 1;
550
- + }// 拡張後の内容を出力(追加領域の値は未定義)
551
- + for (int i = 0; i & lt; 10; ++i) {
552
- + std::cout & lt;& lt; q[i] & lt;& lt; & #39; & #39;;
553
- + }
554
- + std::cout & lt;& lt; std::endl;
555
- + std::free(q);
556
- +}
557
- +```
558
- +## 出力例
559
- +```
560
- +0 1 2 3 4 0 0 0 0 0
561
- +```
562
- +
563
- +
564
- +## 関連項目
565
- +- [`calloc`](calloc.md): メモリを確保する
566
- +- [`malloc`](malloc.md): メモリを確保し、領域をゼロ初期化する
567
- +- [`free`](free.md): 確保したメモリを解放する
568
- < /code>< /pre> </summary >
569
-
570
- <author >
571
- <name >K10-K10</name >
572
-
573
- </author >
574
- </entry >
575
-
576
504
</feed >
0 commit comments