The Wayback Machine - https://web.archive.org/web/20210428173353/https://en.cppreference.com/w/cpp/language/modules
Namespaces
Variants
Views
Actions

Modules (since C++20)

From cppreference.com
< cpp‎ | language
 
 
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function declaration
inline specifier
Exception specifications (until C++20)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
decltype (C++11)
auto (C++11)
alignas (C++11)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Implicit conversions - Explicit conversions
static_cast - dynamic_cast
const_cast - reinterpret_cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous
 
 

Modules help divide large amounts of code into logical parts.

Modules are orthogonal to namespaces.

// helloworld.cpp
export module helloworld;  // module declaration
import <iostream>;         // import declaration
 
export void hello() {      // export declaration
    std::cout << "Hello world!\n";
}
// main.cpp
import helloworld;  // import declaration
 
int main() {
    hello();
}

[edit] Syntax

export(optional) module module-name module-partition(optional) attr(optional) ; (1)
export declaration (2)
export { declaration-seq(optional) } (3)
export(optional) import module-name attr(optional) ; (4)
export(optional) import module-partition attr(optional) ; (5)
export(optional) import header-name attr(optional) ; (6)
module ; (7)
module : private ; (8)
1) Module declaration. Declares that the current translation unit is a module unit.
2,3) Export declaration. Export all namespace-scope declarations in declaration or declaration-seq.
4,5,6) Import declaration. Import a module unit/module partition/header unit.
7) Starts a global module fragment.
8) Starts a private module fragment.

[edit] Keywords

export, import, module