Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
C++26アップデート 2025-03
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Akira Takahashi
April 25, 2025
Technology
2.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
C++26アップデート 2025-03
Akira Takahashi
April 25, 2025
More Decks by Akira Takahashi
See All by Akira Takahashi
P2P通信の標準化 WebRTCを知ろう
faithandbrave
6
3.2k
C++20 射影変換
faithandbrave
0
870
C++26 エラー性動作
faithandbrave
2
1.3k
C++20の整数
faithandbrave
0
300
コンテナと文字列の中間インタフェースspanとstring_view
faithandbrave
1
670
C++23 スタックトレースライブラリ
faithandbrave
0
640
if constexpr文はテンプレート世界のラムダ式である
faithandbrave
3
1.6k
使いたい標準C++機能がない環境でいかに実装・設計するか
faithandbrave
2
1.3k
C++20からC++23までの変化
faithandbrave
9
12k
Other Decks in Technology
See All in Technology
現場の暗黙知を継承するAIエージェント — 対話から生まれる長期記憶と Skills
atsukish
0
220
DMMブックスのNext.js化を加速させるAI活用 / Migrating DMM Books to Next.js with AI
kentarom
1
310
When Token Pruning is Worse than Random: Understanding Visual Token Information in VLLMs
sansantech
PRO
0
230
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
20k
GuardDuty 検知対応を DevOps Agent で効率化しようとしている話 / GuardDuty Investigations with DevOps Agent
masahirokawahara
1
130
AIエージェントを雇う前に決める5つのこと
knishioka
1
140
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3.2k
「重なり」は迎える側がつくる ― 人もAIエージェントも歓迎するプロダクトエンジニアリング ―
go0517go
PRO
0
110
AIで実装は速くなった。なのにプロダクトは速くならない。職能の壁を越えて価値のフローを設計する
nwiizo
0
800
Bet AI Day 2026丨AIによって本質に戻るシステムリスク管理
layerx
PRO
0
580
AI駆動開発を組織で促すために
lycorptech_jp
PRO
7
9.2k
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
510
How STYLIGHT went responsive
nonsquared
100
6.3k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
440
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
320
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
460
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
The Language of Interfaces
destraynor
162
27k
Claude Code のすすめ
schroneko
67
230k
Paper Plane
katiecoart
PRO
2
53k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Transcript
C++26 アップデート 2025-03 高橋 晶 (Akira Takahashi)
[email protected]
Preferred Networks,
Inc. 2025/04/25 (金) C++ MIX #14
C++26 2025-03 • 今回は、2025-03 mailingとしてC++26 Working Draftに入った 変更を紹介していきます • 今回でC++26仕様は一旦できたらしい
• このあとは仕様バグの修正や、各国からのコメントへの対応などがあ る
constexpr unionによる遅延初期化 • 配列要素の初期化を遅延させるための手法 としてunionが使われていたが、constexpr をつけるとコンパイラによって動かなかっ たりした • C++26では明確に許可される template
<class T, int N> class FixedVector { union U { constexpr U() { } constexpr ~U() { } T storage[N]; }; size_t size = 0; … };
タイムトラベル最適化を防止するstd::observable() • DIEを定義しない場合、inc(nullptr)は未 定義動作になることが保証されるため、 bad()をそもそも呼び出さないタイムト ラベル最適化が行われる • C++26ではstd::observable()という関数 でチェックポイントを設定すると、 時間分割されてチェックポイントを跨い
だタイムトラベル最適化が防止される • C++26の標準出力関係にはチェックポ イントが設定される static void bad(const char *msg) { std::fputs(msg, stderr); #ifdef DIE std::abort(); #endif } void inc(int *p) { if(!p) bad("Null! n"); ++*p; // !p時にここで未定義動作 }
契約プログラミング • 3つの契約機能 • 関数の事前条件pre • 関数の事後条件post • 契約アサーションcontract_assert •
postは戻り値に変数名をつけて使用 してもいいし、使用しなくてもいい • pre/postは文脈依存キーワード (変数名とかに使える) • コンパイラに契約モードの設定が追 加される想定 int f(const int x) pre (x != 1) post (r: r == x && r != 2) { contract_assert(x != 3); return x; } void clear() post (empty()) { … }
memory_order::consume関係を非推奨化 • consumeメモリオーダーは、並行プログラムにおいて、 読み込んだ値に依存した操作の実行順序を保証するもの • 実際はconsume相当の順序保証はどのメモリオーダーにも付くのと、 コンパイラがconsume特化の実装をしなかったので非推奨化する • 関連してstd::kill_dependency()と[[carries_dependency]]も非推奨化 std::atomic<T>
x = …; int a = x.load(memory_order::consume); // 非推奨 int b = a + 1; int c = b + 1;
コンセプトと変数テンプレートの テンプレートテンプレートパラメータ対応 • コンセプトと変数テンプレート に、テンプレートテンプレート パラメータが使えるようになる • テンプレートテンプレートパラ メータは、テンプレート引数を あとで指定する機能
template< template <typename T> concept C, template <typename T> auto V > struct S { concept D = C<int>; constexpr auto X = V<int>; }; template <typename T> concept Concept = true; template <typename T> constexpr auto Var = 42; S<Concept, Var> s;
トリビアルな再配置 • trivially relocatable (トリビアルな再 配置) は、memcpyやビットコピーで 再配置ができる性質 • 型にこの性質を与えることで、ムーブ
元オブジェクトのデストラクタ呼び出 しなどを省略できる • そのために文脈依存キーワードが2つ 追加される (それと対応した型特性も) template <class T> class optional trivially_relocatable_if_eligible replaceable_if_eligible { union { T d_object; }; bool d_engaged{false}; … };
#embed : プリプロセス時ファイル読み込み • #includeのように使える ファイル読み込み機能 • 上限のバイト数や、先頭列、末尾列、 空であった場合のデータなどを指定 できる
// 無限サイズのファイル"dev/urandom" // から最大4バイトを読む const unsigned char random[] = { #embed "/dev/urandom" limit(4) }; constexpr int seed = 0; for (int i = 0; i < 4; i++) { seed |= random[i] << (i * 8); } constexpr std::mt19937 gen{seed};
vector / string以外のコンテナをconstexpr対応 • C++20でstd::vectorとstd::stringが constexprで使えるようになった • C++26では、ほかの標準コンテナも すべてconstexpr対応する constexpr
R f() { std::map<std::string, int> m = { … }; if (m.contains("key")) { … } … }
hive : 要素のメモリ位置が安定するシーケンスコンテナ • 双方向Rangeのシーケンスコンテナ std::hiveが追加される • 要素の追加・削除をしても、メモリ位 置は変わらない •
ゲーム、HPC、物理シミュレーション など幅広い分野で使われてきたデータ 構造 std::hive<int> ls = {1, 2, 3}; // 要素を追加。 // {4, 5}の新たなメモリブロックが確保される // {1, 2, 3}のメモリ位置は変わらない ls.insert({4, 5}); // 要素3を削除。 // {4, 5}のメモリ位置は変わらない ls.erase(std::next(ls.begin(), 2));
indirectとpolymorphic : 値の意味論をもつ動的確保オブジェクト • indirectとpolymorphicは、動的確保し たオブジェクトのポインタに、値の意 味論をもたせるもの • コピー時にポインタのコピーではなく、 参照先の値をコピー
(ディープコピー) する • pImplイディオムもunique_ptrの変わり にindirectを使える class ForwardListNode { int data_; indirect<ForwardListNode> next_; }; class ForwardList { indirect<ForwardListNode> head_; }; class Composite { indirect<A> a_; polymorphic<X> x_; public: template <class Derived> Composite(const A& a, const Derived& x) : a_{a}, x_{std::in_place_type<Derived>, x} {} };
今回は以上です! • C++26のアップデートや、 それぞれの機能を掘り下げる発表は 今後もやっていきます