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
Try C++ module! - meetup app osaka@5
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Akiko Kawai
January 29, 2021
Programming
540
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Try C++ module! - meetup app osaka@5
Akiko Kawai
January 29, 2021
More Decks by Akiko Kawai
See All by Akiko Kawai
Unity Scripting Backend - C++breaktime 2026 Summer
harukasao
0
190
C# and C++ Interoperability - cho-dotnetnew
harukasao
0
680
How to call c# from c++ - meetup app osaka@10
harukasao
0
69
VCpp Link and Library - C++ breaktime 2025 Summer
harukasao
0
340
Coding Experience Cpp vs Csharp - meetup app osaka@9
harukasao
0
1.3k
Selected MAUI Blazor - meetup app osaka@8
harukasao
0
200
シミュレーター制作の感想/ Tried developing Simulator at .NET Lab 201910
harukasao
0
130
NimTorchの紹介 / Introduce NimTorch meetup app osaka @3
harukasao
0
940
std::optionalの使い方 / how to use optional nakamecpp_13
harukasao
0
2.7k
Other Decks in Programming
See All in Programming
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
230
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
330
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
360
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
120
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
180
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
330
Performance Optimization With LLMs
xleitix
0
240
AmebaブログはKMPから卒業します
kmars0605
0
330
Crash Auto Pipelines
veronikapj
1
390
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.2k
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
540
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
41k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
350
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
4 Signs Your Business is Dying
shpigford
187
23k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
560
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
650
So, you think you're a good person
axbom
PRO
2
2.3k
Practical Orchestrator
shlominoach
192
12k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
620
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Transcript
/ Try C++ module! Try C++ module! 2021/1/30 Sat meetupapp
osaka @5 遥佐保(はるかさお)
/ 今⽇のお題
/ C++20 modules C++20 modules C++20 で新たに導⼊される module … #include
の代替え⼿段とのことで期待⼤です… これまでのC++のコードの構造と アーキテクチャに ⼤きな影響を与える機能なんじゃ ないかな〜と思います
/ ビルドの流れのおさらい ビルドの流れのおさらい C++のコードから実際に実⾏形式ができるまでの概念
/ そのうち今回関係あるもの プリプロセッサ ヘッダーとソースファイルの分割 コンパイルが開始される前に 翻訳単位(コンパイルの単位)ごとに処理
/ includeの何が問題なの︖ includeの何が問題なの︖ #include “foo.h” はファイルの⽂字列内容を 展開してるだけで、⽂法的な意味はない C# の using
に似てるように⾒えるかもだが全然違う // foo.h class FOO{ int f; }; // main.cpp #include "foo.h" FOO F;
/ <ヘッダーファイルの問題> include する順番の考慮 複数回定義対応のインクルードガード STLなど複雑なテンプレートのコンパイル時間が ⻑くなる そこで module の登場です︕
/ module にするメリット module にするメリット コンパイルされたバイナリに出来る PCHと似たような機能(正式に標準化) export で明⽰的に公開してるものだけが import
で利⽤できる(副作⽤が無い) 既存のヘッダーファイルと共存が可能
/ moduleファイルのサンプル // moduleファイル // 拡張子はなんでも良いけどVC++的には .ixxとしてるみたい // 他のサンプルだと .cppm
が多そう // モジュール名を定義し、それをインポートできるようにします export module NumberCruncher; // module内部で他のmoduleもinport出来る import logger; // module内のマクロは公開されない(汚染がない) #define CRUNCH_FACTOR 3.14
/ moduleファイルのサンプル(続き) namespace numbers { // ↓↓↓明示的にexportされてないので、import側では利用できない float applyCrunchFactor(float number)
{ return number * CRUNCH_FACTOR; } // exportキーワードを書いて、importで利用できるようにする // (これは実装をここに書いてるパターン、他のファイルに実装を分割もできる) export float crunch(float number) { // 内部関数を利用 auto crunched = applyCrunchFactor(number); // 他のmoduleの関数を利用 logger::info("Crunched {} with result of {}", number, crunche return crunched; } }
/ module を利⽤する側 // main.cpp import NumberCruncher; // カスタムmoduleのインポート int
main() { auto value = numbers::crunch(42); }
/ moduleのデメリット moduleのデメリット (と思われている点) includeによるヘッダーファイルの展開がないの で、コンパイル時の解析が早くなるはず… 逆に⾔うと、モジュールの依存関係準にコン パイルする必要があり(今まで出来ていた) コンパイルの並列化がしにくい (普通のPCでビルドする分には早くなると思う
分散環境構築のIncrediBuildさん等は 考慮が必要そうな予感)
/ 今回は最初の使い⽅のみの紹介でした 実際に module を利⽤しようと思ったら 新規概念の「到達可能(Reachable)」の理解や 意図しないODR違反などが出る可能性など 考慮すべき項⽬は多そうです
/ 参考 C++20 in 2020: Modules - Inside PSPDFKit Current
Status - isocpp A Tour of C++ Modules in Visual Studio - C++ Tema Blog https://pspdfkit.com/blog/2020/cpp20-in-2020- modules/ https://isocpp.org/std/status https://devblogs.microsoft.com/cppblog/a-tour-of- cpp-modules-in-visual-studio/
/ C++ のモジュールの概要 - Microsoft Docs モジュール - cpprefjp [C++]モジュール理論
基礎編 - 地⾯を⾒下ろす少年 の⾜蹴にされる私 https://docs.microsoft.com/ja-jp/cpp/cpp/modules- cpp?view=msvc-160 https://cpprefjp.github.io/lang/cpp20/modules.html https://onihusube.hatenablog.com/entry/2019/07/07