Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lang/cpp23/feature_test_macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
## 参照

- [SD-FeatureTest: Feature-Test Macros and Policies - isocpp](https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations)
- [LWG Issue 3621. Remove feature-test macro `__cpp_lib_monadic_optional`](https://cplusplus.github.io/LWG/issue3621)
- C++23で、重複していた`__cpp_lib_monadic_optional`が削除され、代わりに`__cpp_lib_optional`が`202106L`から`202110L`に更新された(`optional`のモナド操作を表す)
- [LWG Issue 3750. Too many papers bump `__cpp_lib_format`](https://cplusplus.github.io/LWG/issue3750)
- C++23で、フォーマットRange系(P2286/P2585)用に`__cpp_lib_format_ranges`(値`202207L`)が追加され、`__cpp_lib_format`とマクロが分離された
- [LWG Issue 3751. Missing feature macro for `flat_set`](https://cplusplus.github.io/LWG/issue3751)
Expand Down
6 changes: 6 additions & 0 deletions reference/filesystem/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ namespace std::filesystem {
|------|------|----------------|
| [`u8path`](u8path.md) | UTF-8エンコードされた文字列からパスオブジェクトを構築する | C++17<br/> C++20で非推奨 |

## ハッシュサポート

| 名前 | 説明 | 対応バージョン |
|------|------|----------------|
| [`hash`](path/hash.md) | `hash`クラスの特殊化 | C++23 |

## 文字列フォーマットサポート

| 名前 | 説明 | 対応バージョン |
Expand Down
66 changes: 66 additions & 0 deletions reference/filesystem/path/hash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# hash
* filesystem[meta header]
* std[meta namespace]
* class template[meta id-type]
* cpp23[meta cpp]

```cpp
namespace std {
template <>
struct hash<std::filesystem::path>;
}
```
* hash[link /reference/functional/hash.md]

## 概要
[`std::hash`](/reference/functional/hash.md)クラスの、[`std::filesystem::path`](../path.md)に対する特殊化。パスの内容からハッシュ値を計算し、`path`を[`unordered_map`](/reference/unordered_map/unordered_map.md)や[`unordered_set`](/reference/unordered_set/unordered_set.md)のキーとして使用できるようにする。

この特殊化はC++23で追加された。それ以前は定義されておらず、`hash<path>`は使用できなかった。


## 効果
`p`を型[`path`](../path.md)のオブジェクトとするとき、`hash<path>()(p)`は[`hash_value`](hash_value.md)`(p)`と同じ値を返す。

したがって、2つのパス`p1`と`p2`について`p1 == p2`であれば、`hash<path>()(p1) == hash<path>()(p2)`となる。


## 例
```cpp example
#include <cassert>
#include <filesystem>
#include <functional>

namespace fs = std::filesystem;

int main()
{
fs::path p = "a/b/c";

// パスの内容からハッシュ値を計算する
std::size_t h = std::hash<fs::path>{}(p);

// hash_valueと同じ値になる
assert(h == fs::hash_value(p));
}
```
* std::hash[color ff0000]
* fs::hash_value[link hash_value.md]

### 出力
```
```


## バージョン
### 言語
- C++23


## 関連項目
- [`std::hash`](/reference/functional/hash.md)
- [`std::filesystem::hash_value`](hash_value.md)


## 参照
- [LWG Issue 3657. `std::hash<std::filesystem::path>` is not enabled](https://cplusplus.github.io/LWG/issue3657)
- C++23で、[`std::hash`](/reference/functional/hash.md)の`path`に対する特殊化が定義された
10 changes: 7 additions & 3 deletions reference/format/basic_format_context/arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

```cpp
basic_format_arg<basic_format_context>
arg(size_t id) const; // (1) C++20
arg(size_t id) const; // (1) C++20
basic_format_arg<basic_format_context>
arg(size_t id) const noexcept; // (1) C++23
constexpr basic_format_arg<basic_format_context>
arg(size_t id) const; // (1) C++26
arg(size_t id) const noexcept; // (1) C++26
```
* basic_format_arg[link /reference/format/basic_format_arg.md]
* basic_format_context[link /reference/format/basic_format_context.md]
Expand All @@ -32,4 +34,6 @@ constexpr basic_format_arg<basic_format_context>

- [P0645R10 Text Formatting](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html)
- [P3391R2 `constexpr std::format`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3391r2.html)
- C++26から`constexpr`に対応した
- C++26から`constexpr`に対応した
- [LWG Issue 3654. `basic_format_context::arg(size_t)` should be `noexcept`](https://cplusplus.github.io/LWG/issue3654)
- C++23で、`noexcept`が付加された
20 changes: 12 additions & 8 deletions reference/format/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ string s3 = format("{} {1}", "a", "b"); // コンパイルエラー
```

* `fill` : アライメントに使う文字 (デフォルト: スペース)
* `align` : アライメント(デフォルトは型による)
* `>` : 右寄せ
* `<` : 左寄せ
* `align` : アライメント
* `>` : 右寄せ。算術型(整数・浮動小数点数)およびポインタ型のデフォルト
* `<` : 左寄せ。非算術型かつ非ポインタ型(文字列など)のデフォルト。`bool`・文字型を整数として出力しない場合もこちら
* `^` : 中央寄せ
* `sign` : 符号
* `+` : 正の数でも符号を表示する
Expand Down Expand Up @@ -146,7 +146,7 @@ string s3 = format("{} {1}", "a", "b"); // コンパイルエラー

デフォルトまたは `s` を指定すると、 `true` / `false` という文字列を出力する。

整数型のオプションも指定できる。その場合は、`unsigned char` に `static_cast` される。
整数型のオプションも指定できる。その場合は、`unsigned char` に `static_cast` される。ただし、C++23以降は `c` (文字として出力)を指定できない(`bool`を文字として出力する意味がないため)。

#### 整数型の場合

Expand Down Expand Up @@ -252,9 +252,9 @@ Range・シーケンスコンテナに対して使用できる標準のオプシ
```

* `fill` : アライメントに使う文字 (デフォルト: スペース)
* `align` : アライメント(デフォルトは型による)
* `align` : アライメント
* `>` : 右寄せ
* `<` : 左寄せ
* `<` : 左寄せ(デフォルト)
* `^` : 中央寄せ
* `width` : 幅 (省略時は値に応じて幅が決まり、アライメントは機能しない)
* 置換フィールドを使って変数で指定できる
Expand Down Expand Up @@ -299,9 +299,9 @@ std::format("{}", m); // {1: "aaa", 2: "bbb"}
```

* `fill` : アライメントに使う文字 (デフォルト: スペース)
* `align` : アライメント(デフォルトは型による)
* `align` : アライメント
* `>` : 右寄せ
* `<` : 左寄せ
* `<` : 左寄せ(デフォルト)
* `^` : 中央寄せ
* `width` : 幅 (省略時は値に応じて幅が決まり、アライメントは機能しない)
* 置換フィールドを使って変数で指定できる
Expand Down Expand Up @@ -750,6 +750,10 @@ wstring format(const locale& loc, wformat_string<Args...> fmt, const Args&... ar
- C++26から、ポインタ値を大文字で出力する`P`オプションが追加された
- [P3391R2 `constexpr std::format`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3391r2.html)
- C++26から非ロケール版が`constexpr`に対応した
- [LWG Issue 3612. Inconsistent pointer alignment in `std::format`](https://cplusplus.github.io/LWG/issue3612)
- C++23で、ポインタ型のデフォルトアライメントが算術型と同じ右寄せに統一された
- [LWG Issue 3648. `format` should not print `bool` with `'c'`](https://cplusplus.github.io/LWG/issue3648)
- C++23で、`bool`に対する型指定オプションから`c`(文字として出力)が除外された
- [LWG Issue 3720. Restrict the valid types of _arg-id_ for _width_ and _precision_ in _std-format-spec_](https://cplusplus.github.io/LWG/issue3720)
- C++23で、幅・精度を動的引数で指定する場合、その引数の型が標準の符号付き/符号なし整数型に制限された(`bool`や文字型は指定できなくなった)
- [LWG Issue 3721. Allow an _arg-id_ with a value of zero for _width_ in _std-format-spec_](https://cplusplus.github.io/LWG/issue3721)
Expand Down
6 changes: 4 additions & 2 deletions reference/format/vformat_to.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ namespace std {
## 効果

書式文字列`fmt`に従ったフォーマットで`args`の文字列表現を出力イテレータ`out`の`[out, out + N)`のイテレータ範囲に出力する。ロケール`loc`が指定された場合は、ロケール依存のフォーマットにおいて使用される。
(ただし、`N`=`formatted_size(fmt, args...)` または `formatted_size(loc, fmt, args...)`)
(ただし、`N`は書式化された文字列表現の文字数)

## 戻り値

`out + N` (ただし、`N`=`formatted_size(fmt, args...)` または `formatted_size(loc, fmt, args...)`)
`out + N` (ただし、`N`は書式化された文字列表現の文字数)

## 例外

Expand Down Expand Up @@ -198,3 +198,5 @@ Out vformat_to(Out out, std::string_view fmt, std::basic_format_args<Context> ar
- [P0645R10 Text Formatting](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html)
- [P3391R2 `constexpr std::format`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3391r2.html)
- C++26から非ロケール版が`constexpr`に対応した
- [LWG Issue 3619. Specification of `vformat_to` contains ill-formed `formatted_size` calls](https://cplusplus.github.io/LWG/issue3619)
- C++23で、効果・戻り値における出力文字数`N`の定義が、不適格な`formatted_size`呼び出しを使わない表現に修正された
6 changes: 4 additions & 2 deletions reference/forward_list/forward_list/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ constexpr void merge(forward_list&& x, Compare comp); // (4) C++26


## 効果
2つのソート済みイテレータ範囲`[begin(), end())`と`[x.begin(), x.end())`をマージする。2つの`forward_list`オブジェクトの要素を`*this`に併合し、`x`はマージ後に空となる。
[`addressof`](/reference/memory/addressof.md)`(x) == this`である場合、何もしない。そうでない場合、2つのソート済みイテレータ範囲`[begin(), end())`と`[x.begin(), x.end())`をマージする。2つの`forward_list`オブジェクトの要素を`*this`に併合し、`x`はマージ後に空となる。

マージ後、`x`の要素に対するイテレータおよび参照は無効にならない。

Expand All @@ -47,7 +47,7 @@ constexpr void merge(forward_list&& x, Compare comp); // (4) C++26


## 計算量
高々[`distance`](/reference/iterator/distance.md)`(`[`begin`](begin.md)()`,` [`end`](end.md)`()) +` [`distance`](/reference/iterator/distance.md)`(x.`[`begin`](begin.md)`(), x.`[`end`](end.md)`()) - 1`回の比較
[`addressof`](/reference/memory/addressof.md)`(x) == this`である場合、比較を行わない。そうでない場合、高々[`distance`](/reference/iterator/distance.md)`(`[`begin`](begin.md)()`,` [`end`](end.md)`()) +` [`distance`](/reference/iterator/distance.md)`(x.`[`begin`](begin.md)`(), x.`[`end`](end.md)`()) - 1`回の比較


## 備考
Expand Down Expand Up @@ -102,3 +102,5 @@ int main()
- [LWG Issue 2122. `merge()` stability for lists versus forward lists](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2122)
- [LWG Issue 2123. `merge()` allocator requirements for lists versus forward lists](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2123)
- [P3372R3 constexpr containers and adaptors](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3372r3.html)
- [LWG Issue 3088. `forward_list::merge` behavior unclear when passed `*this`](https://cplusplus.github.io/LWG/issue3088)
- C++23で、`x`が`*this`自身である場合は何もしないことが明確化された
4 changes: 4 additions & 0 deletions reference/iterator/contiguous_iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ C++20で導入された`contiguous_iterator`は、要素がメモリー上で連
`a, b`を間接参照可能なイテレータ、`c`を間接参照不可能なイテレータとし、`b`は`a`から、`c`は`b`からそれぞれ到達可能であるとする。そのような型`I`のイテレータ`a, b, c`と[`iter_difference_t<I>`](/reference/iterator/iter_difference_t.md)の示す型`D`について次の条件を満たす場合に限って、型`I`は`contiguous_iterator`のモデルである。

## 要件
- [`ranges::iter_move`](/reference/iterator/iter_move.md)`(a)`は、`std::move(*a)`と同じ型・値カテゴリ・効果を持つ
- [`ranges::iter_swap`](/reference/iterator/iter_swap.md)`(a, b)`が適格である場合、その効果は[`ranges::swap`](/reference/concepts/swap.md)`(*a, *b)`と等価である
- C++26: このイテレータの範囲`[i, s)`はポインタ範囲`[to_address(i), to_address(i + ranges::distance(i, s)))`に置き換えて使用することが実装に許可される
- 注:このイテレータをアルゴリズム適用した場合、イテレータのインクリメントが一回しか起こらない可能性があり、個々のインクリメントに対して副作用を起こすことを期待してはならない
- 備考:連続イテレータの範囲に対する操作として、`std::copy()`の実装が[`std::memmove()`](/reference/cstring/memmove.md)の呼び出しで完了するなど、イテレータを一つずつ進めるのではなくメモリ操作で高速実装されることを許可するものである
Expand Down Expand Up @@ -114,5 +116,7 @@ std::ostream_iterator<double> is not contiguous_iterator
- [P0896R4 The One Ranges Proposal (was Merging the Ranges TS)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0896r4.pdf)
- [P1474R1 Helpful pointers for `ContiguousIterator`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1474r1.pdf)
- [P3349R1 Converting contiguous iterators to pointers](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3349r1.html)
- [LWG Issue 3607. `contiguous_iterator` should not be allowed to have custom `iter_move` and `iter_swap` behavior](https://cplusplus.github.io/LWG/issue3607)
- C++23で、`ranges::iter_move`・`ranges::iter_swap`がデフォルトの挙動と一致することがモデル要件に追加された
- [LWG Issue 4170. `contiguous_iterator` should require `to_address(I{})`](https://cplusplus.github.io/LWG/issue4170)
- C++26で、`to_address`を要求する`requires`式の対象が`const I&`であることが整理された(cpprefjpの記述はもともとこの形と一致している)
9 changes: 6 additions & 3 deletions reference/iterator/counted_iterator/op_increment.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
* cpp20[meta cpp]

```cpp
constexpr counted_iterator& operator++(); // (1)
constexpr counted_iterator& operator++(); // (1) C++20

decltype(auto) operator++(int); // (2)
decltype(auto) operator++(int); // (2) C++20
constexpr decltype(auto) operator++(int); // (2) C++23

constexpr counted_iterator operator++(int)
requires forward_iterator<I>; // (3)
requires forward_iterator<I>; // (3) C++20
```

## 概要
Expand Down Expand Up @@ -97,5 +98,7 @@ int main() {

## 参照
- [P0896R4 The One Ranges Proposal (was Merging the Ranges TS)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0896r4.pdf)
- [LWG Issue 3643. Missing `constexpr` in `std::counted_iterator`](https://cplusplus.github.io/LWG/issue3643)
- C++23で、後置インクリメント(2)に`constexpr`が追加された
- [P3697R1 Minor additions to C++26 standard library hardening](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3697r1.html)
- [P3878R1 Standard library hardening should not use the 'observe' semantic](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3878r1.html)
21 changes: 20 additions & 1 deletion reference/memory/atomic.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,27 @@ namespace std {
これらの特殊化を使用することで、共通のスマートポインタオブジェクトに対する複数スレッドでの操作をアトミックに行える。


## 定数初期化
C++23で`constexpr atomic(nullptr_t) noexcept`コンストラクタが追加され、非アトミックな`shared_ptr`・`weak_ptr`と同様に、[`constinit`](/lang/cpp20/constinit.md)を使って`nullptr`から定数初期化できるようになった:

```cpp
// グローバル変数を、動的初期化ではなく定数初期化する
constinit std::atomic<std::shared_ptr<int>> g_resource{nullptr};
```

非アトミックな`shared_ptr`では`constinit std::shared_ptr<int> p{nullptr};`が可能であったが、C++20時点の`atomic<shared_ptr<T>>`は`nullptr`を受け取るコンストラクタ経路(`nullptr`から一時オブジェクトの`shared_ptr`を構築し、`atomic(shared_ptr<T>)`コンストラクタに渡す)が`constexpr`でなかったため、`constinit`による定数初期化ができなかった。この非対称性が解消された。

`constinit`による定数初期化には以下の利点がある:

- **静的初期化順序問題 (static initialization order fiasco) の回避** : グローバル・名前空間スコープのオブジェクトを動的初期化すると、ほかの翻訳単位のグローバル変数の初期化との実行順序が未規定となり、初期化前のオブジェクトにアクセスしてしまう危険がある。定数初期化されるオブジェクトはプログラム開始前に初期化が完了しているため、どの動的初期化よりも先に初期化済みであることが保証され、この問題を避けられる
- **動的初期化のオーバーヘッド排除** : 実行時に初期化コードが走らない


### 共通メンバ関数
| 名前 | 説明 | 対応バージョン |
|------|------|-----|
| [`(constructor)`](/reference/atomic/atomic/op_constructor.md) | コンストラクタ | C++20 |
| `constexpr atomic(nullptr_t) noexcept` | `nullptr`から構築する | C++23 |
| `~atomic() = default` | デストラクタ | C++20 |
| [`operator=`](/reference/atomic/atomic/op_assign.md) | 代入演算子 | C++20 |
| [`is_lock_free`](/reference/atomic/atomic/is_lock_free.md) | オブジェクトがロックフリーに振る舞えるかを判定する | C++20 |
Expand Down Expand Up @@ -110,4 +127,6 @@ int main()
- [P0718R2 Revising `atomic_shared_ptr` for C++20](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0718r2.html)
- [cplusplus/draft #2824 - add forward declaration of `atomic` class for `atomic<shared_ptr<T>>` (P0718R2)](https://github.com/cplusplus/draft/pull/2824)
- [P1644R0 Add wait/notify to `atomic<shared_ptr<T>>`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1644r0.html)
- [P3037R6 `constexpr std::shared_ptr` and friends](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3037r6.pdf)
- [P3037R6 `constexpr std::shared_ptr` and friends](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3037r6.pdf)
- [LWG Issue 3661. `constinit atomic<shared_ptr<T>> a(nullptr);` should work](https://cplusplus.github.io/LWG/issue3661)
- C++23で、`nullptr`から構築する`constexpr atomic(nullptr_t) noexcept`コンストラクタが追加された
2 changes: 2 additions & 0 deletions reference/memory/unique_ptr/op_constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,6 @@ int main()
- [LWG Issue 2520 : N4089 broke initializing `unique_ptr<T[]>` from a nullptr](https://wg21.cmeerw.net/lwg/issue2520)
- [LWG Issue 2801. Default-constructibility of `unique_ptr`](https://wg21.cmeerw.net/lwg/issue2948)
- [LWG Issue 2905. `is_constructible_v<unique_ptr<P, D>, P, D const &>` should be false when D is not copy constructible](https://wg21.cmeerw.net/lwg/issue2905)
- [LWG Issue 3632. `unique_ptr` "_Mandates_: This constructor is not selected by class template argument deduction"](https://cplusplus.github.io/LWG/issue3632)
- C++23で、クラステンプレート実引数推論(CTAD)による選択を防ぐ仕様が、Mandates指定から引数型を`type_identity_t<pointer>`とする方式へ書き換えられた(観測可能な振る舞いは変わらない)
- [P2273R3 Making `std::unique_ptr` constexpr](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2273r3.pdf)
Loading
Loading