It's been considered for a reason, that using for namespaces/names is side-effect-prone, and generally, fully qualified names should be preferred.
I've come up with an approach on that, which I couldn't find implemented yet, so I created my own project.
Briefly, the idea is to define a set of macro which would unfold into the following structure:
namespace your_namespace { namespace __local__ { //includes and other non-exported names go here namespace __exported__ { //actual code goes here } } using namespace __local__::__exported__; } It isolates the contents of __local__ from your_namespace, while keeping them visible to it's logically-actual part.
General usage looks like this:
#include <namespace_util.hpp> NAMESPACE(foo) //here go using declarations, and the names you don't want to be visible from outside NAMESPACE_EXPORTS //here go your namespace members NAMESPACE_END The implementation:
#define NAMESPACE(name)\ namespace name {\ namespace __local__ {\ #define NAMESPACE_EXPORTS\ namespace __exported__ { #define NAMESPACE_END\ }\ }\ using namespace __local__::__exported__;\ } Since I'm relatively new to C++, I can't be completely sure about the solution, so I ask the people: please see the (much more detailed) README, the code, and give your feedback.
Thank you.
usingfor namespaces/names is side-effect-prone" What is side-effect-prone supposed to mean?usingjust allows you to refer to things without the qualified name, it's perfectly usable in individual translation units, and you can minimize issues byusingspecific functions/classes/etc. rather than the whole namespace (using namespacedoes basically defeat the purpose of namespaces, if that's what you meant). In fact, if you want to do proper ADL withstd::swapyou needusing std::swapinside your swap implementations.