3

As the title suggests, I was wondering what other reasons, purposes or uses are there for the PImpl idiom other than reducing rebuild times.

Quoting an example from here:

(thread locals need to be behind a pimpl wall; they can't be exported directly

I don't understand what the user means, but I gather there are other interesting uses for the PImpl idiom,

Torrie Merk
  • 105
  • 1
  • 8
  • 1
    This means that thread local variables should not exist in the declaration files as this causes the issues described in the Ticket. Also another benefit of using PImpl is reducing dependencies. – N. Gerontidis Feb 23 '17 at 08:23
  • @N.Gerontidis you could perhaps write your reducing dependencies comment as an answer and elaborate a little more. – Torrie Merk Feb 23 '17 at 08:28

1 Answers1

4

From the book "Effective C++ Third Edition" by Scott Meyers (Item 31)

"The key to this separation is replacement of dependencies on definitions with dependencies on declarations. That’s the essence of minimizing compilation dependencies: make your header files self-sufficient whenever it’s practical, and when it’s not, depend on declarations in other files, not definitions."

For example in this case, moving the thread local variable to the definition file there is one less compilation dependency because the thread_local.hpp is not included in the declaration file.