I just discovered this old C++0x draft about modules in C++0x.
The idea was to get out of the current .h/.cpp system by writing only .cpp files which would then generate module files during compilation, which would then in turn be used by the other .cpp files.
This looks like a really great feature.
But my question is: why did they remove it from C++0x? Was it because of too many technical difficulties? Lack of time? And do you think they will consider working on it for an ulterior version of C++?
A draft and several updated revisions for the C/C++ module specification have been published by WG21 on open-std.org. I will link only to the latest documents here:
The following blog posts contain a summary of the standards meetings and in particular a summary of the current status of the modules draft:
Update: As explained in the Kona trip report that I linked to above, there are currently two competing proposals, one from Microsoft and one from Clang. The proposed solution from Microsoft does not allow to export Macros, while the solution from the Clang team would support exporting Macros. So far only Microsoft has formally submitted a draft for a module specification.
Here is a quick overview of the most important concepts that this proposal contains. As its a draft this might possibly still change. The new modules standard will among other things consist of the following:
A module
keyword to declare a module, multiple files can declare this to build one module (but for each module only one compilation-unit can contain an export {}
section):
module M;
An import
keyword to import modules, instead of import
it might also be decided to use using module
instead, so a new import keyword could be avoided.
import std.io;
import module.submodule;
An export
syntax, which defines the public declarations that are part of this module, non-interface declarations that should not be exported as part of the module will be defined outside the export block. Declarations can be any kind of declaration in C/C++, that is, not only functions but also variables, structs, templates, namespaces and classes:
export {
int f(int);
double g(double, int);
int foo;
namespace Calc {
int add(int a, int b);
}
}
void not_exported_function(char* foo);
An important change of modules will be that macros and preprocessor definitions will be local to modules and will not be exported. Thus macros do not have any impact on imported modules:
#define FILE "my/file"
import std.io; //will not be impacted by the above definition
Its important note that the both the current preprocessor system and modules will be able to co-exist and headers can still be used for example to include macros.
For more detailed information I suggest to read the draft.
Clang has been working on a modules implementation which can be found at the clang modules page. However clang does currently not implement a concrete syntax for modules, that is, none of the above mentioned syntax has been implemented by Clang. To explain this the page contains the following statement:
At present, there is no C or C++ syntax for import declarations. Clang will track the modules proposal in the C++ committee. See the section Includes as imports to see how modules get imported today.
The main part that is currently implemented by Clang is the "Module Map Language" which allows write module maps for existing code that still uses header files.
As mentioned above it is still unclear if macro exports will be part of the final Modules TS. In P0273R1 the following syntax was proposed for the export of macros:
#export define MAX(A,B) ((A) > (B)) ? (A) : (B);
From the State of C++ Evolution (Post San Francisco 2008), the Modules proposal was categorized as "Heading for a separate TR:"
These topics are deemed too important to wait for another standard after C++0x before being published, but too experimental to be finalised in time for the next Standard. Therefore, these features will be delivered by a technical report at the earliest opportunity.
The modules proposal just wasn't ready and waiting for it would have delayed finishing the C++0x standard. It wasn't really removed, it was just never incorporated into the working paper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With