C++ Logo


Advanced search

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

From: Zopolis0 <creatorsmithmdt_at_[hidden]>
Date: Sat, 3 Sep 2022 16:09:24 +1000
On further research, P2615R0 appears to present a solution to this under
its #[module.interface] modifications.

On Mon, Aug 15, 2022 at 5:46 PM Zopolis0 <creatorsmithmdt_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.
> 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-09-03 06:09:38