A C++ module partition is a structural mechanism introduced in C++20 that allows a single module to be divided across multiple translation units. Partitions enable the logical separation of a module’s declarations and definitions into distinct files while presenting a single, unified module to external consumers. They are strictly internal to the owning module; external code can only import the primary module, never its individual partitions. The syntactic delimiter for a partition is a colon (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
:), formatted as PrimaryModuleName:PartitionName.
There are two distinct types of module partitions: Interface Partitions and Implementation Partitions.
Interface Partitions
An interface partition contains declarations (and potentially definitions) that are intended to be part of the primary module’s public API. It is declared using theexport module keywords followed by the partition name.
export import :PartitionName;.
Implementation Partitions
An implementation partition contains internal logic, helper functions, or definitions that are strictly private to the module. It does not contribute to the public API. It is declared using themodule keyword (without export) followed by the partition name.
import :PartitionName;. They cannot be exported.
The Primary Module Interface
The primary module interface acts as the aggregator for all partitions. It defines the module’s name and dictates exactly what is exposed to the consumer.Architectural Rules and Constraints
- Internal Visibility: The syntax
import :PartitionName;is only valid within translation units belonging to the same primary module. External translation units must useimport PrimaryModuleName;. - Export Obligation: If an interface partition (
export module M:P;) exists, it must be exported (export import :P;) by the primary module interface. Failure to do so renders the program ill-formed. - No Sub-partitions: The partition syntax does not support nesting. A declaration like
export module math:addition:integers;is syntactically invalid. - Acyclic Dependencies: Partitions within the same module form a dependency graph that must be a Directed Acyclic Graph (DAG). Cyclic imports between partitions (e.g.,
:Aimports:B, and:Bimports:A) are ill-formed. - Implicit Imports: An implementation unit of a module (e.g.,
module math;) implicitly imports the primary module interface, but it does not implicitly import the module’s partitions. Partitions must be explicitly imported where needed.
Master C++ with Deep Grasping Methodology!Learn More





