SlideShare a Scribd company logo
Overview of C++20 and a
deeper look into modules
export module cpp20;
export bool doModulesRock()
{
return true;
}
Overview of C++20 and a deeper look into modules
Speaker
● Marius Meisenzahl
● Co-founder of
○ located in Bochum
○ we build software from embedded to web
○ we offer training for
■ testing
■ software architecture
■ DevOps
■ ...
2
/meisenzahl /meisenzahl
Overview of C++20 and a deeper look into modules
C++20
Core Language Library Concurrency
Four
The Big Five
● Three-way comparison
operator
● Strings literals as template
parameters
● constexpr virtual functions
● Redefinition of volatile
● Designated initializers
● Various lambda improvements
● New standard attributes
● consteval and constinit
keyword
● std=:source_location
● Calendar and
time-zone
● std=:span as a
view on a
contiguous array
● constexpr
containers such
as std=:string
and
std=:vector
● std=:format
● std=:atomic_ref<T>
● std=:atomic<std=:shared_ptr<T=>
and
std=:atomic<std=:weak_ptr<T=>
● Floating point atomics
● Waiting on atomics
● Semaphores, latches and barriers
● std=:jthread
● Concepts
● Contracts
● Coroutines
● Ranges
● Modules
3
Overview of C++20 and a deeper look into modules
Core Language > std=:source_location
● Provides access to file name, line number, ...
● Modern alternative to preprocessor macros like =_FILE=_ and =_LINE=_
● Prime candidate for custom logging functionality in combination with
std=:format
https://en.cppreference.com/w/cpp/utility/source_location
4
Overview of C++20 and a deeper look into modules
Library > std=:format
● https://github.com/fmtlib/fmt is integrated into C++
● Python like string formatting
● Define formatting rules for custom types
fmt=:print("Hello, {}!", "world");
std=:string s = fmt=:format("I'd rather be {1} than {0}.", "right", "happy");
5
Overview of C++20 and a deeper look into modules
Concurrency > std=:jthread
● A new kind of std=:thread
● Can automatically join
● Can be interrupted
○ std=:interrupt_token
https://www.modernescpp.com/index.php/a-new-thread-with-c-20-std-jthread
6
Overview of C++20 and a deeper look into modules
Contracts
int push(queue& q, int val)
[[ expects: !q.full() ]]
[[ ensures !q.empty() ]]
{
==.
[[assert: q.is_ok() ]]
==.
}
https://www.reddit.com/r/cpp/comments/cmk7ek/what_happened_to_c20_contracts/
7
Precondition
Postcondition
Assertion
Overview of C++20 and a deeper look into modules
Concepts
● Extension of templates
○ specify which semantic categories are allowed
● Templates can be used more expressive
● Check types during compile time
○ “is sortable”, “is equality comparable”, …
https://www.modernescpp.com/index.php/c-20-concepts-the-details
8
Overview of C++20 and a deeper look into modules
Coroutines
● Asynchronous programming
○ cooperative multitasking, event loops, ...
○ new keywords co_await and co_yield
==.
size_t n = co_await socket.async_read_some(buffer(data));
co_await async_write(socket, buffer(data, n));
==.
https://en.cppreference.com/w/cpp/language/coroutines
9
Overview of C++20 and a deeper look into modules
Ranges
● Apply algorithms of STL on containers
○ connect them with pipe operator
● Use infinite data streams
auto children_names =
all_people
| filter([](const auto& person) { return person.age < 14; })
| transform([](const auto& person) { return person.name; })
| to_vector;
https://vector-of-bool.github.io/2019/10/21/rngs-static-ovr.html
10
Overview of C++20 and a deeper look into modules
Modules
● Alternative to header and implementation files
○ can halve the number of files in the code base
● No more include guards and/or #pragma once
○ But you can also separate between interface and implementation
● Faster compilation times?!
○ “Reduce build times due to not reparsing large header files”
■ https://gcc.gnu.org/wiki/cxx-modules
○ http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1441r1.pdf
● Isolation of preprocessor macros
● Better way to express which parts of a library are exported
https://vector-of-bool.github.io/2019/03/10/modules-1.html
11
Overview of C++20 and a deeper look into modules
Modules > Names
module-name:
[module-name-qualifier] identifier ;
module-name-qualifier:
identifier "." | module-name-qualifier identifier "." ;
=> speech | speech.english
12
Overview of C++20 and a deeper look into modules
Modules > Declaration
module-declaration:
["export"] "module" module-name [module-partition] [attribute-specifier-seq] ";" ;
module-partition:
":" module-name ;
=> export module example;
13
Overview of C++20 and a deeper look into modules
Modules > Partitions and “Submodules”
Partitions
export module speech;
export import :english;
export import :spanish;
“Submodules” → Separate modules
export module speech;
export import speech.english;
export import speech.spanish;
14
Overview of C++20 and a deeper look into modules
Modules > Interfaces
hello.cppm
export module hello;
export const char *greet() { return "Hello, world!"; }
15
Overview of C++20 and a deeper look into modules
Modules > Interfaces and Implementations
hello.cppm
export module hello;
export const char *greet();
hello.cpp
module hello;
const char *greet()
{ return "Hello, world!"; }
16
Overview of C++20 and a deeper look into modules
Modules > What can be exported?
● namespace
● class
● struct
● non-static variables/constants
● ...
Understanding C++ Modules: Part 2: export, import, visible, and reachable
17
Overview of C++20 and a deeper look into modules
Modules > Interoperability
Every compiler uses it’s own binary format. You
can not interchange the precompiled modules.
https://www.reddit.com/r/cpp/comments/d5dxr3/do_c20_modules_have_a_st
andard_binary_format_if/
18
Overview of C++20 and a deeper look into modules
Compiler support
TL;DR: WIP
https://en.cppreference.com/w/cpp/compiler_support
https://clang.llvm.org/cxx_status.html
https://gcc.gnu.org/projects/cxx-status.html
https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conform
ance?view=vs-2019
19
Overview of C++20 and a deeper look into modules
Resources
● https://isocpp.org/
● http://www.open-std.org/jtc1/sc22/wg21/docs/papers/
● https://en.wikipedia.org/wiki/C%2B%2B20
● https://www.reddit.com/r/cpp/comments/cfk9de/201907_cologne_iso_c_committee_trip_report_the/
● https://docs.microsoft.com/en-us/cpp/cpp/cpp-language-reference
● https://en.cppreference.com/w/
● https://vector-of-bool.github.io/
● https://blog.panicsoftware.com/
● http://modernescpp.com/
20

More Related Content

PDF
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
PDF
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
PPTX
Kostiantyn Grygoriev "Wrapping C++ for Python"
PPTX
P/Invoke - Interoperability of C++ and C#
PDF
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
PDF
[C++ korea] effective modern c++ study item 4 - 6 신촌
PPTX
C language
PDF
C++ Programming - 11th Study
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
Kostiantyn Grygoriev "Wrapping C++ for Python"
P/Invoke - Interoperability of C++ and C#
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
[C++ korea] effective modern c++ study item 4 - 6 신촌
C language
C++ Programming - 11th Study

What's hot (8)

PDF
PPTX
Roslyn: el futuro de C#
PPTX
Operator overloading2
PDF
Objective-C Runtime overview
DOC
Labsheet 6 - FP 201
PPTX
C Programming Training In Ambala ! BATRA COMPUTER CENTRE
PDF
29. Treffen - Tobias Meier - TypeScript
PDF
Codejunk Ignitesd
Roslyn: el futuro de C#
Operator overloading2
Objective-C Runtime overview
Labsheet 6 - FP 201
C Programming Training In Ambala ! BATRA COMPUTER CENTRE
29. Treffen - Tobias Meier - TypeScript
Codejunk Ignitesd
Ad

Similar to Overview of C++20 and a deeper look into modules (20)

PDF
Introduction-to-C-Part-1.pdf
PDF
Антон Бикинеев, Writing good std::future&lt; C++ >
PDF
Beyond C++17
PPTX
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
PPTX
Introduction-to-C-Part-1.pptx
PDF
Object Oriented Programming using C++ PCIT102.pdf
PDF
Writing good std::future&lt;c++>
PDF
Writing good std::future&lt;c++>
PPT
11 cpp
PDF
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
DOC
Introduction-to-C-Part-1 (1).doc
PPTX
C++ helps you to format the I/O operations like determining the number of dig...
PPTX
C++Basics2022.pptx
PPTX
С++ without new and delete
PDF
С++ without new and delete
PPTX
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
PDF
How to create an Angular builder
PPTX
Lab 1.pptx
PPTX
Intro to c++
PDF
Debugging and Profiling C++ Template Metaprograms
Introduction-to-C-Part-1.pdf
Антон Бикинеев, Writing good std::future&lt; C++ >
Beyond C++17
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1.pptx
Object Oriented Programming using C++ PCIT102.pdf
Writing good std::future&lt;c++>
Writing good std::future&lt;c++>
11 cpp
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
Introduction-to-C-Part-1 (1).doc
C++ helps you to format the I/O operations like determining the number of dig...
C++Basics2022.pptx
С++ without new and delete
С++ without new and delete
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
How to create an Angular builder
Lab 1.pptx
Intro to c++
Debugging and Profiling C++ Template Metaprograms
Ad

Recently uploaded (20)

PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administration Chapter 2
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
medical staffing services at VALiNTRY
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Introduction to Artificial Intelligence
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
AI in Product Development-omnex systems
PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
L1 - Introduction to python Backend.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms II-SECS-1021-03
Odoo POS Development Services by CandidRoot Solutions
System and Network Administration Chapter 2
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
How Creative Agencies Leverage Project Management Software.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
medical staffing services at VALiNTRY
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Wondershare Filmora 15 Crack With Activation Key [2025
Introduction to Artificial Intelligence
Online Work Permit System for Fast Permit Processing
VVF-Customer-Presentation2025-Ver1.9.pptx
AI in Product Development-omnex systems
Introduction Database Management System for Course Database
Design an Analysis of Algorithms I-SECS-1021-03
ManageIQ - Sprint 268 Review - Slide Deck
How to Migrate SBCGlobal Email to Yahoo Easily
L1 - Introduction to python Backend.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41

Overview of C++20 and a deeper look into modules

  • 1. Overview of C++20 and a deeper look into modules export module cpp20; export bool doModulesRock() { return true; }
  • 2. Overview of C++20 and a deeper look into modules Speaker ● Marius Meisenzahl ● Co-founder of ○ located in Bochum ○ we build software from embedded to web ○ we offer training for ■ testing ■ software architecture ■ DevOps ■ ... 2 /meisenzahl /meisenzahl
  • 3. Overview of C++20 and a deeper look into modules C++20 Core Language Library Concurrency Four The Big Five ● Three-way comparison operator ● Strings literals as template parameters ● constexpr virtual functions ● Redefinition of volatile ● Designated initializers ● Various lambda improvements ● New standard attributes ● consteval and constinit keyword ● std=:source_location ● Calendar and time-zone ● std=:span as a view on a contiguous array ● constexpr containers such as std=:string and std=:vector ● std=:format ● std=:atomic_ref<T> ● std=:atomic<std=:shared_ptr<T=> and std=:atomic<std=:weak_ptr<T=> ● Floating point atomics ● Waiting on atomics ● Semaphores, latches and barriers ● std=:jthread ● Concepts ● Contracts ● Coroutines ● Ranges ● Modules 3
  • 4. Overview of C++20 and a deeper look into modules Core Language > std=:source_location ● Provides access to file name, line number, ... ● Modern alternative to preprocessor macros like =_FILE=_ and =_LINE=_ ● Prime candidate for custom logging functionality in combination with std=:format https://en.cppreference.com/w/cpp/utility/source_location 4
  • 5. Overview of C++20 and a deeper look into modules Library > std=:format ● https://github.com/fmtlib/fmt is integrated into C++ ● Python like string formatting ● Define formatting rules for custom types fmt=:print("Hello, {}!", "world"); std=:string s = fmt=:format("I'd rather be {1} than {0}.", "right", "happy"); 5
  • 6. Overview of C++20 and a deeper look into modules Concurrency > std=:jthread ● A new kind of std=:thread ● Can automatically join ● Can be interrupted ○ std=:interrupt_token https://www.modernescpp.com/index.php/a-new-thread-with-c-20-std-jthread 6
  • 7. Overview of C++20 and a deeper look into modules Contracts int push(queue& q, int val) [[ expects: !q.full() ]] [[ ensures !q.empty() ]] { ==. [[assert: q.is_ok() ]] ==. } https://www.reddit.com/r/cpp/comments/cmk7ek/what_happened_to_c20_contracts/ 7 Precondition Postcondition Assertion
  • 8. Overview of C++20 and a deeper look into modules Concepts ● Extension of templates ○ specify which semantic categories are allowed ● Templates can be used more expressive ● Check types during compile time ○ “is sortable”, “is equality comparable”, … https://www.modernescpp.com/index.php/c-20-concepts-the-details 8
  • 9. Overview of C++20 and a deeper look into modules Coroutines ● Asynchronous programming ○ cooperative multitasking, event loops, ... ○ new keywords co_await and co_yield ==. size_t n = co_await socket.async_read_some(buffer(data)); co_await async_write(socket, buffer(data, n)); ==. https://en.cppreference.com/w/cpp/language/coroutines 9
  • 10. Overview of C++20 and a deeper look into modules Ranges ● Apply algorithms of STL on containers ○ connect them with pipe operator ● Use infinite data streams auto children_names = all_people | filter([](const auto& person) { return person.age < 14; }) | transform([](const auto& person) { return person.name; }) | to_vector; https://vector-of-bool.github.io/2019/10/21/rngs-static-ovr.html 10
  • 11. Overview of C++20 and a deeper look into modules Modules ● Alternative to header and implementation files ○ can halve the number of files in the code base ● No more include guards and/or #pragma once ○ But you can also separate between interface and implementation ● Faster compilation times?! ○ “Reduce build times due to not reparsing large header files” ■ https://gcc.gnu.org/wiki/cxx-modules ○ http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1441r1.pdf ● Isolation of preprocessor macros ● Better way to express which parts of a library are exported https://vector-of-bool.github.io/2019/03/10/modules-1.html 11
  • 12. Overview of C++20 and a deeper look into modules Modules > Names module-name: [module-name-qualifier] identifier ; module-name-qualifier: identifier "." | module-name-qualifier identifier "." ; => speech | speech.english 12
  • 13. Overview of C++20 and a deeper look into modules Modules > Declaration module-declaration: ["export"] "module" module-name [module-partition] [attribute-specifier-seq] ";" ; module-partition: ":" module-name ; => export module example; 13
  • 14. Overview of C++20 and a deeper look into modules Modules > Partitions and “Submodules” Partitions export module speech; export import :english; export import :spanish; “Submodules” → Separate modules export module speech; export import speech.english; export import speech.spanish; 14
  • 15. Overview of C++20 and a deeper look into modules Modules > Interfaces hello.cppm export module hello; export const char *greet() { return "Hello, world!"; } 15
  • 16. Overview of C++20 and a deeper look into modules Modules > Interfaces and Implementations hello.cppm export module hello; export const char *greet(); hello.cpp module hello; const char *greet() { return "Hello, world!"; } 16
  • 17. Overview of C++20 and a deeper look into modules Modules > What can be exported? ● namespace ● class ● struct ● non-static variables/constants ● ... Understanding C++ Modules: Part 2: export, import, visible, and reachable 17
  • 18. Overview of C++20 and a deeper look into modules Modules > Interoperability Every compiler uses it’s own binary format. You can not interchange the precompiled modules. https://www.reddit.com/r/cpp/comments/d5dxr3/do_c20_modules_have_a_st andard_binary_format_if/ 18
  • 19. Overview of C++20 and a deeper look into modules Compiler support TL;DR: WIP https://en.cppreference.com/w/cpp/compiler_support https://clang.llvm.org/cxx_status.html https://gcc.gnu.org/projects/cxx-status.html https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conform ance?view=vs-2019 19
  • 20. Overview of C++20 and a deeper look into modules Resources ● https://isocpp.org/ ● http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ ● https://en.wikipedia.org/wiki/C%2B%2B20 ● https://www.reddit.com/r/cpp/comments/cfk9de/201907_cologne_iso_c_committee_trip_report_the/ ● https://docs.microsoft.com/en-us/cpp/cpp/cpp-language-reference ● https://en.cppreference.com/w/ ● https://vector-of-bool.github.io/ ● https://blog.panicsoftware.com/ ● http://modernescpp.com/ 20