C++ Logo

std-proposals

Advanced search

[std-proposals] Export namespaces without namespace block, only keyword (modules)

From: Zopolis0 <creatorsmithmdt_at_[hidden]>
Date: Mon, 15 Aug 2022 17:46:12 +1000
In short-- I propose that there should be a way (if not multiple) to export
functions within a namespace from a module without having to wrap the
functions in a namespace block.
A few possibilities for the syntax of doing so are presented below, along
with the rationale.
Suggestions for alternative/additional syntaxes or improvements on the ones
proposed would be welcome.
Briefly:
Instead of
export module foo;

export namespace foo
{
  void bar();
}
Allow the usage of
export module foo;
export namespace foo void bar();

Haven't really decided on the breadth of the syntax and how many ways there
would be to declare the namespace, was thinking about a file-wide namespace
declaration along the lines of:
export module foo:
export namespace foo;
This would set everything exported from module foo to be in namespace foo.
This of course would not work for multiple namespaces in a file, for which
the original keyword proposition could be used as a fallback.

Rationale:
Namespaces are cool. (I see no reason to provide a rationale for the usage
of namespaces in this proposal.)
When using headers, it is quite easy to make the functions accessible
through namespaces without wrapping the entire file in a namespace block.
Simply wrap the list of functions in the header in a namespace block and
prepend the namespace onto the functions in the file.

With modules, one has to wrap the entire file in a namespace block, or at
least the functions they want to export, which is sub-par.

Received on 2022-08-15 07:46:25