3

I've tried to use an implementation namespace, but when i 'using namespace' it, it pulls in the whole implementation namespace, rendering it useless.

namespace library {
 namespace implementation {
  //implementation
 }

 using namespace implementation

 //visible identifiers
}

Is there way to hide implementation, without needing to use "implementation::" before using anything from implementation?

1
  • 6
    Don't use using namespace implementation;? Commented May 27, 2016 at 13:42

1 Answer 1

9

rendering it useless

Well, it's not useless, you just can't using namespace it. You have to explicitly prepend implementation:: to the names in it. For this reason, it might make sense to choose a shorter name (detail is commonly used in c++ projects for this purpose).

Also, I'd like to point out that header-only and implementation hiding are two somewhat conflicting requirements. If you truly need to hide the implementation, you can't go header-only.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, then i'll use macros (which i'll undef at the end of the header) to prepend identifiers from implementation.
@G_glop it's your code, but I don't see an advantage of using a macro for this.
Just a thought, maybe only for some widely used types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.