1

I've often found myself in a situation where a 3rd party library could use some features or utilities that do not currently exist. In writing those companion utilties, the question arises as to which namespace to put them in.

I've picked a convention to shadow the 3rd party's namespace within my own, but I've not entirely convinced myself that there aren't unwanted repercussions lurking.

Example utility header:

#include <third_party/Thing.hpp>

namespace my_namespace
{
    namespace third_party
    {
        typedef ::third_party::Thing<int,3> Thing3i
    }
}

So the question is: Are there any significant negative consequences of doing this?

Catskul
  • 17,916
  • 15
  • 84
  • 113

1 Answers1

0

I don't particularly see anything wrong but I would caution that you do not pollute your namespace with the 3rd party one in case of ambiguity or bloat, there is a good answer to this issue with whether it is a good idea to nest namespaces: C++ namespaces advice, Nested NameSpaces in C++ and here Usage of namespaces in c++.

In general it should be safe and I would restrict using namespace third_party usage to just cpp files, otherwise if you were to declare using namespace third_party in your header then the code that #includes your header will accidentally acquire the third party namespace unless you really want that to happen.

Community
  • 1
  • 1
EdChum
  • 376,765
  • 198
  • 813
  • 562
  • I'm not sure if I misunderstand your answer, but I don't see a risk of polluting my namespace here. This sort of thing would be declared in a utility header and then used elsewhere without needing any `using namespace` – Catskul Apr 11 '12 at 22:28
  • @Catskul, sorry for not being clear, what you are proposing is safe so long as you don't pollute your namespace by declaring `using namespace third_party` in your headers. – EdChum Apr 11 '12 at 22:30
  • Ok, I misunderstood. I didn't realize you were making a general statement about `using namespace` (not necessarily related to the given example specifically). – Catskul Apr 11 '12 at 22:36