C++ Logo


Advanced search

Re: Was there ever proposal/discussion of private namespace or private using?

From: Matthew Woehlke <mwoehlke.floss_at_[hidden]>
Date: Fri, 14 Jun 2019 17:21:38 -0400
On 14/06/2019 16.50, Ivan Matek via Std-Proposals wrote:
> first of all I will say that I know that C++ normally looks at TU as a
> bunch of characters(produced by preprocessor), not as a group of files.
> That being said:
> was there ever any discussion/proposals regarding 2 related features:
> //headery_mcheaderface.h
> private using namespace std; // applies to ONLY this file, files that
> include headery_mcheaderface.h will not get polluted, nice for making
> declarations shorter

As you noted, C++ doesn't work on files, it works on TU's.

Anyway, I think modules solves this...

> //headery_mcheaderface.
> private namespace {
> void util_fn1(int x){
> // ...
> }
> }
> private namespace limits the visibility of util_fn to the file in which it
> is declared, meaning that compiler can forget about it after last line of
> the source in which it is declared.

...and this. Basically, I don't see any non-modules way for the compiler
to "forget" things at include boundaries, and *with* modules, well,
things already work the way you want. This was, in fact, one of the
primary motivations for modules.


Received on 2019-06-14 16:23:27