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++20からC++23までの変化
Search
Akira Takahashi
December 06, 2023
Programming
12k
9
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
C++20からC++23までの変化
Akira Takahashi
December 06, 2023
More Decks by Akira Takahashi
See All by Akira Takahashi
P2P通信の標準化 WebRTCを知ろう
faithandbrave
6
3.3k
C++20 射影変換
faithandbrave
0
920
C++26アップデート 2025-03
faithandbrave
0
2.3k
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
Other Decks in Programming
See All in Programming
AWSに止められる覚悟してますか?
morizo_1984
2
520
速習iPhone Duo対応
yuukiw00w
2
970
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
120
気持ちぃ〜角丸 Squircle
ryu1013
0
150
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
8
5.6k
AIに “答え“を書かせるのを やめてみた
___akari11
0
110
すこし踏み込む CancellationToken
htkym
2
1.7k
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
450
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
910
残高管理から台帳サービスへの進化
artoy
0
180
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
130
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
A better future with KSS
kneath
240
18k
Faster Mobile Websites
deanohume
310
32k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Documentation Writing (for coders)
carmenintech
77
5.6k
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Navigating Weather and Climate Data
rabernat
0
550
Transcript
$ ͔Β$ ·Ͱͷ มԽ ߴڮ থ "LJSB5BLBIBTIJ GBJUIBOECSBWF!HNBJMDPN 1SFGFSSFE/FUXPSLT *OD
ਫ $ .*9
͡Ίʹ • લճͷ$ .*9͕ͩͬͨͷͰɺ$ ͷ͕͋·Γ Ͱ͖͍ͯ·ͤΜͰͨ͠ • ͳͷͰࠓճɺ$ ͷ͓͞Β͍ͱɺ$ ͷ͔ΜͨΜͳ
հΛ͠·͢
͜Ε·ͰͷओͳΞοϓσʔτ༰Λ͓͞Β͍ バージョン 主なアップデート内容 C++98 (1998年) ISOで標準化された最初のバージョン C++03 (2003年) C++98で未規定だった仕様の補完 (C++98と同じだと考えていい)
C++11 (2011年) 初期化⼦リスト、範囲for⽂、型推論、ラムダ式、スレッド、 スマートポインタなど C++14 (2014年) 2進数リテラル、数値リテラルの桁区切り⽂字など C++17 (2017年) 構造化束縛、optionalクラス、インライン変数、ファイルシステム など C++20 (2020年) ⽐較演算⼦の⾃動定義、⽂字列フォーマット、Range、 テンプレートパラメータの制約、数学定数など
$ ൺֱԋࢉࢠͷࣗಈఆٛ • operator==Λఆٛ͢Δͱɺoperator!=͕ࣗಈఆٛ͞ΕΔ • operator<=>Λఆٛ͢Δͱɺoperator<ɺoperator<=ɺ operator>ɺoperator>=͕ࣗಈఆٛ͞ΕΔ • operator<=> ͷਖ਼໊ࣜশʮUISFFXBZ
DPNQBSJTPOPQFSBUPS ࡾํൺֱԋࢉࢠ ʯɻӉધԋࢉࢠͱݴ͏ • memcmpؔͱಉ͡Α͏ʹɺ͍͔͠ɺখ͍͔͞ɺେ͖͍͔Λ ҰʹఆͰ͖Δ
$ จࣈྻϑΥʔϚοτ • std::format͕ؔೖͬͨ • 1ZUIPO෩ͷॻࣜจࣈྻΛ͍ɺॻࣜࢦఆͷจࣈྻΛੜͰ͖Δ • QSJOUGͷΑ͏ʹܕΛॻࣜͰࢦఆͤͣɺҾ൪߸ ॻࣜΛࢦఆ͢Δ •
ostringstreamΛ͏ඞཁ͕ ͍͍ͩͨ ͳ͘ͳͬͨ • ॻࣜจࣈྻɺίϯύΠϧ࣌ʹνΣοΫ͞ΕΔ • constevalͳίϯετϥΫλʹΑͬͯจࣈྻϦςϥϧͷίϯύΠϧ࣌νΣοΫ Λ࣮ݱ͍ͯ͠Δ cout << format("{} {} {}", 3, 1.23, "hello") << endl; cout << format("{0} {0:#x} {1}", 15, "hello") << endl; 3 1.23 hello 15 0xf hello
$ 3BOHF • ίϯςφΠςϨʔλൣғͳͲͷ3BOHFʹର͢Δૢ࡞͕ఆٛ͞Εͨ • <ranges>ͰͷԆධՁͷ3BOHFΞμϓλʹՃ͑ͯɺ<algorithm>ͷ3BOHF൛ ͕std::ranges໊લۭؒʹఆٛ͞ΕΔ • ಈతʹɺ৽نΞϧΰϦζϜstd::ranges໊લۭؒʹͷΈఆٛ͞ΕΔ༷ •
$ Ͱ3BOHFΞμϓλ͕͞Βʹͨ͘͞ΜೖͬͨɻΠϯσοΫε͖Ͱϧʔϓ͢Δ enumerateͱ͔ͱ͔ vector v = {1, 2, 3, 4, 5}; for (auto x : v | filter([](int x) { return x % 2 == 0 }) | transform([](int x) { return x * 3; })) { cout << x << endl; }
$ ֶఆ • <numbers>ϔομʹɺstd::numbers::piͳͲͷֶఆ͕ఆٛ͞ΕΔ • $ ίϯύΠϧ࣌ͷؔධՁ DPOTUFYQS • $
มςϯϓϨʔτ • $ ΠϯϥΠϯม ϔομʹมఆ࣮ٛͯ͠ମΛͻͱͭʹͰ͖Δ • $ ίϯηϓτ • pi͕double൛ɺpi_v͕ςϯϓϨʔτ൛ template <class T> T degree_to_radian(T x) { return x * std::numbers::pi_v<T> / static_cast<T>(180.0); } template <class T> inline constexpr T pi_v = static_cast<T>(3.14159265358979323846L);
$ • std::print() / std::println() • import std; •
std::expected • ίϧʔνϯΛศརʹ͏ͨΊͷstd::generatorΫϥε
$ QSJOUQSJOUMO • std::format()ϕʔεͷग़ྗؔͱͯ͠ɺ std::print()ͱstd::println()͕ೖͬͨ • std::println()վߦίʔυ͖ • <print>ϔομʹσϑΥϧτͷΦʔόʔϩʔυͱɺ'*-& ͷΦʔόʔ
ϩʔυ͕ఆٛ͞ΕΔ • <ostream>ϔομʹstd::ostream&ͷΦʔόʔϩʔυ͕ఆٛ͞ΕΔ • ͨͩ͠ɺstd::cerrͱ͔<iostream>Ͱఆٛ͞ΕΔͷͰҙ println("{} {} {}", 3, 1.23, "hello"); println("{0} {0:#x} {1}", 15, "hello"); 3 1.23 hello 15 0xf hello
$ JNQPSUTUE • ඪ४Ϟδϡʔϧͱͯ͠ɺstdͱstd.compat͕ೖͬͨ • stdɺ$ޓϥΠϒϥϦΛؚΉશ෦ೖΓͰɺશ෦TUE໊લۭؒʹೖΔ • std.compatɺ$ޓϥΠϒϥϦΛάϩʔόϧ໊લۭؒʹೖΕΔ • ͲͪΒશ෦ೖΓ
• ͨͩ͠ɺϚΫϩؚ·Εͳ͍ͷͰassertͱ͔͕ඞཁͳΒΠϯΫϧʔυ͕ ՃͰඞཁ import std; int main() { std::println("Hello World"); }
$ FYQFDUFE • ਖ਼ৗ͔ΤϥʔͲͪΒ͔͕ೖΔܕͱͯ͠TUEFYQFDUFE͕ೖΔ • FYQFDUFEJOU TUSJOHͩͬͨΒਖ਼ৗJOUɺΤϥʔTUSJOH • FYQFDUFETUSJOH TUSJOHͰ͖Δ
expected<double, string> safe_divide(double i, double j) { if (j == 0) { return unexpected("divide by zero"); } else { return i / j; } } if (auto r = safe_divide(3.0, 2.0); r.has_value()) { r.value(); // 正常値を取り出してなにかする } else { r.error(); // エラー値を取り出してなにかする }
$ HFOFSBUPS • $ ͷίϧʔνϯΛΑΓ͔ΜͨΜʹ͑Δػೳͱͯ͠TUEHFOFSBUPS5 Ϋϥε͕ೖͬͨ • ੜͨ͠Λ3BOHFͱͯ͑͠Δ // 偶数値の無限Rangeを作る関数
std::generator<int> evens() { int n = 0; while (true) { co_yield n; n += 2; } } // 先頭5個だけ使う for (int i : evens() | std::views::take(5)) {}
·ͱΊ • $ ͱ$ ͰɺීஈͷϓϩάϥϛϯάΛΑΓ؆୯ʹ͢Δ ػೳ͕ͨ͘͞ΜೖΓ·ͨ͠ • $ ͷΞοϓσʔτʹ͍͍͚ͭͯͳ͘ͳΔํ૿͑ͯ͘Δͱ ࢥ͏ͷͰɺใൃ৴͕ΜΓ·ͬ͢
εϙϯαʔืूத • IUUQTDQQSFGKQHJUIVCJP • $ ຊޠϦϑΝϨϯεαΠτDQQSFGKQͷεϙϯαʔืूΛ ։࢝͠·ͨ͠ • $ ͷ࠷৽ใΛ࣋ଓతʹൃ৴͍ͯͨ͘͠Ίʹαϙʔτ͍ͯ͠
͚ͨͩΔํΛืू͓ͯ͠Γ·͢ • ͍͍͓ͨͩͨۚɺฤूऀʹ͠·͢