Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
C++26アップデート 2025-03
Search
Akira Takahashi
April 25, 2025
Technology
2.3k
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.3k
C++20 射影変換
faithandbrave
0
920
C++26 エラー性動作
faithandbrave
2
1.3k
C++20の整数
faithandbrave
0
310
コンテナと文字列の中間インタフェースspanとstring_view
faithandbrave
1
680
C++23 スタックトレースライブラリ
faithandbrave
0
650
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
しろおびから始める!ログ活用の第一歩
shumei_ito
0
290
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
220
OpenSharing について熱く語る〜AI アセットの共有について〜
kameitomohiro
0
230
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
0
130
ai_cording_with_k8s_knowledge.pdf
mochizuki875
1
300
3つのアプローチで目指す チームを強くするAI駆動開発
thkt
0
120
購入ドメインでの課題と取り組み
ykagano
0
150
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
150
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
1
730
全社共通データ基盤をつくる。ソニーのDatabricks活用とデータガバナンス設計の裏側
sony
0
430
AI Made Us Faster at Solving the Wrong Problems
marceloancelmo
0
180
IR Today: Theory, Practice, and Agents
dtunkelang
0
350
Featured
See All Featured
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
720
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Raft: Consensus for Rubyists
vanstee
142
7.7k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
530
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.3k
BBQ
matthewcrist
90
10k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
It's Worth the Effort
3n
188
29k
The Curious Case for Waylosing
cassininazir
1
560
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Google's AI Overviews - The New Search
badams
0
1.6k
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
860
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のアップデートや、 それぞれの機能を掘り下げる発表は 今後もやっていきます