File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed
Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -15,25 +15,27 @@ C++26では、共用体 (`union`) のデフォルトコンストラクタとデ
1515これにより、非トリビアルな型のメンバをもつ共用体を未初期化のストレージとして` constexpr ` の文脈で使用できるようになる。
1616
1717``` cpp
18- template <typename T, size_t N>
18+ template <typename T, std:: size_t N>
1919struct FixedVector {
20- union { T storage[ N] ; };
21- size_t size = 0;
20+ union { T storage[ N] ; };
21+ std:: size_t size = 0;
2222
23- // C++23まで: unionのコンストラクタ/デストラクタが削除されるためコンパイルエラー
24- // C++26: OK。unionのコンストラクタ/デストラクタはトリビアル
25- constexpr FixedVector() = default;
23+ // C++23まで: unionのコンストラクタ/デストラクタが削除されるためコンパイルエラー
24+ // C++26: OK。unionのコンストラクタ/デストラクタはトリビアル
25+ constexpr FixedVector() = default;
2626
27- constexpr ~FixedVector() {
28- std::destroy(storage, storage + size);
29- }
27+ constexpr ~ FixedVector() {
28+ std::destroy(storage, storage + size);
29+ }
3030
31- constexpr auto push_back (T const& v) -> void {
32- std::construct_at(storage + size, v);
33- ++size;
34- }
31+ constexpr auto push_back(T const& v) -> void {
32+ std::construct_at(storage + size, v);
33+ ++size;
34+ }
3535};
3636```
37+ * std::construct_at[link /reference/memory/construct_at.md]
38+ * std::destroy[link /reference/memory/destroy.md]
3739
3840
3941## 仕様
You can’t perform that action at this time.
0 commit comments