|
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>2026-09-15T18:24:12.152847</updated> |
6 | | - <id>50576c6c-b19d-4d32-b099-b0cd19b81dec</id> |
| 5 | + <updated>2026-09-16T01:56:08.415564</updated> |
| 6 | + <id>296840ba-a07a-4f57-a37e-212c3c4d2ac0</id> |
7 | 7 |
|
8 | 8 |
|
| 9 | + <entry> |
| 10 | + <title>atomic_store_or -- atomic_store_or : 出力の間違いを修正</title> |
| 11 | + <link href="https://cpprefjp.github.io/reference/atomic/atomic_store_or.html"/> |
| 12 | + <id>b9fc76bb279738bd15e3e1bce573f6659fe2717d:reference/atomic/atomic_store_or.md</id> |
| 13 | + <updated>2026-09-16T10:54:02+09:00</updated> |
| 14 | + |
| 15 | + <summary type="html"><pre><code>diff --git a/reference/atomic/atomic_store_or.md b/reference/atomic/atomic_store_or.md |
| 16 | +index 44de359f8..15d164703 100644 |
| 17 | +--- a/reference/atomic/atomic_store_or.md |
| 18 | ++++ b/reference/atomic/atomic_store_or.md |
| 19 | +@@ -76,7 +76,7 @@ int main() |
| 20 | + |
| 21 | + ### 出力 |
| 22 | + ``` |
| 23 | +-0b0101 |
| 24 | ++0b1101 |
| 25 | + ``` |
| 26 | + |
| 27 | + |
| 28 | +</code></pre></summary> |
| 29 | + |
| 30 | + <author> |
| 31 | + <name>Akira Takahashi</name> |
| 32 | + <email>faithandbrave@gmail.com</email> |
| 33 | + </author> |
| 34 | + </entry> |
| 35 | + |
9 | 36 | <entry> |
10 | 37 | <title>コンストラクタ -- fix in ambiguous convertion</title> |
11 | 38 | <link href="https://cpprefjp.github.io/reference/chrono/zoned_time/op_constructor.html"/> |
@@ -454,189 +481,6 @@ index d18207ac8..b5a3ae3cc 100644 |
454 | 481 |
|
455 | 482 | ```cpp example |
456 | 483 | #include &lt;type_traits&gt; |
457 | | -</code></pre></summary> |
458 | | - |
459 | | - <author> |
460 | | - <name>Akira Takahashi</name> |
461 | | - <email>faithandbrave@gmail.com</email> |
462 | | - </author> |
463 | | - </entry> |
464 | | - |
465 | | - <entry> |
466 | | - <title>constexpr if 文 [P0292R2] -- Merge pull request #1260 from cpprefjp/refactor/cwg2518</title> |
467 | | - <link href="https://cpprefjp.github.io/lang/cpp17/if_constexpr.html"/> |
468 | | - <id>437e7550bfa7198efb270a555edb0cf7f3c4b12e:lang/cpp17/if_constexpr.md</id> |
469 | | - <updated>2026-09-15T16:05:27+09:00</updated> |
470 | | - |
471 | | - <summary type="html"><pre><code>diff --git a/lang/cpp17/if_constexpr.md b/lang/cpp17/if_constexpr.md |
472 | | -index e67a44ecd..d18207ac8 100644 |
473 | | ---- a/lang/cpp17/if_constexpr.md |
474 | | -+++ b/lang/cpp17/if_constexpr.md |
475 | | -@@ -76,57 +76,57 @@ void f(Out&amp; o, A1 const&amp; a1, A2 const&amp; a2) |
476 | | - それでも記述が実際にしたい処理に比べて不必要に複雑になる。 |
477 | | - constexpr if文の導入によりそのような複雑な手法を用いずに素直に条件付きのコンパイルを実現できるようになった。 |
478 | | - |
479 | | --### 2段階名前探索における注意点 |
480 | | -- |
481 | | --`constexpr if`文で、実行されない方の`statement`は廃棄文(discarded statement)となり、文の実体化を防ぐ。言い換えると、2段階名前探索における依存名(dependent name)は、廃棄文の場合検証されない。また文が実体化されないのだから通常のif文と同じくもちろん実行時に実行もされない。つまり次の例は意図と異なる挙動を示す。 |
482 | | -+`constexpr if`文の条件式内は実体化が起きる。したがって実体化するとコンパイルエラーになるものは書いてはいけない。 |
483 | | - |
484 | | - ```cpp example |
485 | | - #include &lt;type_traits&gt; |
486 | | -+#include &lt;iostream&gt; |
487 | | -+ |
488 | | -+struct Hoge { |
489 | | -+ using type = int; |
490 | | -+}; |
491 | | - |
492 | | - template &lt;typename T&gt; |
493 | | --void f(T) |
494 | | -+void f() |
495 | | - { |
496 | | -- if constexpr (std::is_same_v&lt;T, int&gt;) |
497 | | -- { |
498 | | -- // Tがintのときのみ評価されてほしい |
499 | | -- // 実際は常に評価される |
500 | | -- static_assert(false); |
501 | | -+ if constexpr (std::is_same_v&lt;typename T::type, int&gt; || std::is_same_v&lt;typename T::value_type, int&gt;) { |
502 | | -+ std::cout &lt;&lt; &#34;is int&#34; &lt;&lt; std::endl; |
503 | | - } |
504 | | - } |
505 | | - |
506 | | - int main() |
507 | | - { |
508 | | -- f(2.4); |
509 | | -- f(3); |
510 | | -+ f&lt;Hoge&gt;(); //error: Hoge::value_typeは存在しないのでif constexpr文の条件式がコンパイルエラーになる |
511 | | - } |
512 | | - ``` |
513 | | - |
514 | | --なぜならば廃棄文はテンプレートの実体化を防ぐ (依存名の検証をしない) だけで、非依存名は検証されるからである。この例の[`static_assert`](/lang/cpp11/static_assert.md)に渡す条件式はテンプレートパラメータに依存していないので、テンプレートの宣言時に検証され、エラーとなる。言い換えれば`static_assert`に渡す条件式が依存名ならばテンプレートの宣言時に検証されず、テンプレート実体化まで評価を遅らせることができる。 |
515 | | -- |
516 | | --```cpp example |
517 | | --#include &lt;type_traits&gt; |
518 | | -+### `static_assert`宣言に関する例外 |
519 | | - |
520 | | --template &lt;typename T&gt; |
521 | | --constexpr bool false_v = false; |
522 | | -+後に述べる2段階名前探索に関する注意点とは関係なく、C++23以降、もしくはCWG 2518が適用された環境においては、template文(もしくは適切な特殊化や`constexpr if`文の中の文)が実際に実体化されない限り、`static_assert`宣言による失敗は無視される。 |
523 | | - |
524 | | --template &lt;typename T&gt; |
525 | | --void f(T) |
526 | | --{ |
527 | | -- if constexpr (std::is_same_v&lt;T, int&gt;) |
528 | | -- { |
529 | | -- // Tがintのときのみ評価される |
530 | | -- static_assert(false_v&lt;T&gt;); |
531 | | -+```cpp example |
532 | | -+#include &lt;cstdint&gt; |
533 | | -+template &lt;class T&gt; |
534 | | -+void f(T t) { |
535 | | -+ if constexpr (sizeof(T) == sizeof(std::int32_t)) { |
536 | | -+ use(t); |
537 | | -+ } else { |
538 | | -+ static_assert(false, &#34;must be 32bit&#34;); |
539 | | - } |
540 | | - } |
541 | | - |
542 | | --int main() |
543 | | --{ |
544 | | -- f(2.4); |
545 | | -- f(3); |
546 | | -+void g(std::int8_t c) { |
547 | | -+ std::int32_t n = 0; |
548 | | -+ f(n); // OK: nはstd::int32_t型なので`use(t);`のほうが実体化されるために、static_assert宣言の失敗は無視される。 |
549 | | -+ f(c); // error: cはstd::int8_t型なので、static_assert宣言は失敗し、&#34;must be 32bit&#34;とコンパイラが診断メッセージを出力する |
550 | | - } |
551 | | - ``` |
552 | | - |
553 | | --上の例では`false_v`を作ったが、ラムダ式でも同様のことができる。ラムダ式はそれが記述された位置から見て最小のスコープ (ブロックスコープ/クラススコープ/名前空間スコープ) で宣言されるクラスとして扱われる。例えば、下の例では`f()`という関数テンプレート内で宣言される。関数テンプレート内のクラスは依存名になるため、テンプレートの宣言時に検証されず、テンプレート実体化まで評価を遅らせることができる。 |
554 | | -+### 2段階名前探索における注意点 |
555 | | -+ |
556 | | -+`constexpr if`文で、実行されない方の`statement`は廃棄文(discarded statement)となり、文の実体化を防ぐ。言い換えると、2段階名前探索における依存名(dependent name)は、廃棄文の場合検証されない。また文が実体化されないのだから通常のif文と同じくもちろん実行時に実行もされない。 |
557 | | -+ |
558 | | -+CWG 2518が適用されていない環境においては`static_assert`を用いる時に直感的ではない挙動を示していた。 |
559 | | - |
560 | | - ```cpp example |
561 | | - #include &lt;type_traits&gt; |
562 | | -@@ -136,8 +136,9 @@ void f(T) |
563 | | - { |
564 | | - if constexpr (std::is_same_v&lt;T, int&gt;) |
565 | | - { |
566 | | -- // Tがintのときのみ評価される |
567 | | -- static_assert([]{return false;}()); |
568 | | -+ // Tがintのときのみ評価されてほしい |
569 | | -+ // 実際は常に評価される |
570 | | -+ static_assert(false); |
571 | | - } |
572 | | - } |
573 | | - |
574 | | -@@ -148,51 +149,32 @@ int main() |
575 | | - } |
576 | | - ``` |
577 | | - |
578 | | --`constexpr if`文の条件式内は実体化が起きる。したがって実体化するとコンパイルエラーになるものは書いてはいけない。 |
579 | | -+なぜならば廃棄文はテンプレートの実体化を防ぐ (依存名の検証をしない) だけで、非依存名は検証されるからである。この例の[`static_assert`](/lang/cpp11/static_assert.md)に渡す条件式はテンプレートパラメータに依存していないので、テンプレートの宣言時に検証され、エラーとなる。 |
580 | | -+ |
581 | | -+#### CWG 2518が適用されていない環境での回避策 |
582 | | -+ |
583 | | -+言い換えれば`static_assert`に渡す条件式が依存名ならばテンプレートの宣言時に検証されず、テンプレート実体化まで評価を遅らせることができる。 |
584 | | - |
585 | | - ```cpp example |
586 | | - #include &lt;type_traits&gt; |
587 | | --#include &lt;iostream&gt; |
588 | | - |
589 | | --struct Hoge { |
590 | | -- using type = int; |
591 | | --}; |
592 | | -+template &lt;typename T&gt; |
593 | | -+constexpr bool false_v = false; |
594 | | - |
595 | | - template &lt;typename T&gt; |
596 | | --void f() |
597 | | -+void f(T) |
598 | | - { |
599 | | -- if constexpr (std::is_same_v&lt;typename T::type, int&gt; || std::is_same_v&lt;typename T::value_type, int&gt;) { |
600 | | -- std::cout &lt;&lt; &#34;is int&#34; &lt;&lt; std::endl; |
601 | | -+ if constexpr (std::is_same_v&lt;T, int&gt;) |
602 | | -+ { |
603 | | -+ // Tがintのときのみ評価される |
604 | | -+ static_assert(false_v&lt;T&gt;); |
605 | | - } |
606 | | - } |
607 | | - |
608 | | - int main() |
609 | | - { |
610 | | -- f&lt;Hoge&gt;(); //error: Hoge::value_typeは存在しないのでif constexpr文の条件式がコンパイルエラーになる |
611 | | --} |
612 | | --``` |
613 | | -- |
614 | | --### (CWG 2518が適用された環境) `static_assert`文に関する例外 |
615 | | -- |
616 | | --上に述べたように、`constexpr if`文の中の文は廃棄文においても、非依存名の検証を行う。このため特に`static_assert`文を使う時に直感的ではない挙動を示していた。 |
617 | | -- |
618 | | --C++23以降、もしくはCWG 2518が適用された環境においては、template文(もしくは適切な特殊化や`constexpr if`文の中の文)が実際にインスタンス化されるまで、`static_assert`文の宣言は遅延される。 |
619 | | -- |
620 | | --```cpp example |
621 | | --#include &lt;cstdint&gt; |
622 | | --template &lt;class T&gt; |
623 | | --void f(T t) { |
624 | | -- if constexpr (sizeof(T) == sizeof(std::int32_t)) { |
625 | | -- use(t); |
626 | | -- } else { |
627 | | -- static_assert(false, &#34;must be 32bit&#34;); |
628 | | -- } |
629 | | --} |
630 | | -- |
631 | | --void g(std::int8_t c) { |
632 | | -- std::int32_t n = 0; |
633 | | -- f(n); // OK: nはstd::int32_t型なので`use(t);`のほうがインスタンス化されるために、static_assert文は宣言されない。 |
634 | | -- f(c); // error: cはstd::int8_t型なので、static_assert文は宣言され、&#34;must be 32bit&#34;とコンパイラが診断メッセージを出力する |
635 | | -+ f(2.4); |
636 | | -+ f(3); |
637 | | - } |
638 | | - ``` |
639 | | - |
640 | 484 | </code></pre></summary> |
641 | 485 |
|
642 | 486 | <author> |
|
0 commit comments