A Module Implementation Unit (Aegean)
This module is still tiny, with only two files in it; one is a Module Interface Unit (MIU) and the other a Module Implementation Unit.
Module Interface Unit: Aegean.cppm
The MIU is Aegean.cppm.
1 module;
2
3 export module Aegean;
4
5 export auto νιάου() -> void;
There are three changes from the last chapter:
- The definition of
miyāwi()is removed, - The declaration of
νιάου()is added (line 5), - The global fragment is empty since no headers are required.
With an empty fragment the module; statement may be omitted and the export (line 3) statement sufficient. I would include it as a convention. It may avoid a recompilation or two when you add a preprocessor statement after an import or export module statement.
Module Implementation Unit: aegean.cpp
The next file is a Module Implementation Unit.
1 module;
2
3 #include <print>
4
5 module Aegean;
6
7 auto νιάου() -> void {
8 std::println("Η Αιγαιόγατα λέει νιάου");
9 }
The module; (line 1) statement indicates it is part of a module. It is required here to start the global fragment to include the <print> header (line 3).
The implementation declares it is part of a specific module with module Aegean (line 5) statement. Finally, the function νιάου()(line 7) is defined.
User Code: main.cpp
The main.cpp is the same as for Abyssimian in the last chapter except for changing the module name and function name.
1 import Aegean;
2
3 auto main() -> int {
4 νιάου();
5 return 0;
6 }