Is there a proposal to extend the C++ language so as to obviate pimpl?

349 Views Asked by At

Sometimes, you want to provide a class declaration, which is not merely an opaque forward declaration but has the public functionality exposed - yet you don't want to commit to your private, or implementation-specific, fields and methods. One solution for this is the pimpl idiom - using a pointer to an inner class, housing the implementation of the class exposed publicly.

I don't really like using pimpl and wish the language would allow you to have really-private members - so that code using the class does not 'see' their declaration (and thus probably doesn't need to be recompiled when the implementation details change). Also, recently, I've noticed C++ has been evolving much faster - a 3-year tick-tock pattern in standard updates. So... is there a proposal to add such functionality to C++? Do some compilers currently support it perhaps?

1

There are 1 best solutions below

1
On BEST ANSWER

Yes, such a proposal exists. There were even several previous versions, the most current one is from last year:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4173.pdf

The proposal would allow operator. to be overloaded, listing several use-cases:

  • Smart references
  • Smart pointer work-alikes
  • Proxies
  • Interface refinement
  • Pimpl
  • Handles

You can read the linked proposal for more information. Of course, this will not necessarily be accepted and, even if it is accepted, it will probably not make it into C++17.