C++ Logo


Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 15 Aug 2022 10:01:16 -0400
On Mon, Aug 15, 2022 at 3:46 AM Zopolis0 via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> 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.

Why do you need a shorter way to say that? Namespace names and module
names probably *shouldn't* always be the same. It would make it
difficult to use sub-modules, where multiple modules contribute to one
larger module.

> 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.

Why is that "sub-par"?

Received on 2022-08-15 14:01:40