Date: Fri, 14 Jun 2019 22:50:34 +0200
Hi,
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
//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.
In other words this does what currently we do with lib_namespace*::detail::*
convention, but does not rely on convention, and *may *speed up
compilation, since compiler can forget about all the types and functions.
Downside is that this would encourage huge file implementations instead of
proper partitioning into multiple files since namespace could only be
visible in one file or in all that transitively include it.
More complicated solutions like ability to delete namespace could be used
in that case, but that might be too complicated.
//first lines of my_vector.h
#include my_vector_impl.h // contains many my_vector::detail functions and
types
//last lines of my_vector.h file
delete namespace my_vector::detail; // now compiler can drop every type and
function from namespace my_vector::detail, namespace my_vector is unaffected
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
//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.
In other words this does what currently we do with lib_namespace*::detail::*
convention, but does not rely on convention, and *may *speed up
compilation, since compiler can forget about all the types and functions.
Downside is that this would encourage huge file implementations instead of
proper partitioning into multiple files since namespace could only be
visible in one file or in all that transitively include it.
More complicated solutions like ability to delete namespace could be used
in that case, but that might be too complicated.
//first lines of my_vector.h
#include my_vector_impl.h // contains many my_vector::detail functions and
types
//last lines of my_vector.h file
delete namespace my_vector::detail; // now compiler can drop every type and
function from namespace my_vector::detail, namespace my_vector is unaffected
Received on 2019-06-14 15:52:36