1

I've run into an issue trying to keep my implementation details out of reach of the user when writing templates because they reside in headers.

In a typical .cpp file, implementation details can be completely hidden by using internal linkage through inline namespaces or the static keyword. But, this doesn't do much in headers since they're not separate translation units.

What I've settled on is having an implementation namespace, and just assuming that the user won't be inclined to mess with it. But, I'd rather not give the user an option to see it at all. Is this possible?

What I currently do:

//template_stuff.hpp

namespace impl {
  // stuff used in code below
}

namespace project {
 // templates that use entities in ::impl
}

A question I have for the future is if modules will resolve this issue for me. I hope so, but I don't know enough details about the final design to conclude this.

Anthony
  • 1,015
  • 8
  • 22
  • Ask yourself if the code you want to hide need to be a template and why? I think that in properly designed code you rarely need both at the same time and same level of abstraction. – Phil1970 Apr 22 '19 at 13:08
  • @Phil1970 the code I want to hide isn't a template, but is used in a template which means it needs to be in the header. – Anthony Apr 22 '19 at 13:30

0 Answers0