Pimpl's are a source of boilerplate in a lot of C++ code. They seem like the kind of thing that a combination of macros, templates, and maybe a little external tool help could solve, but I'm not sure what the easiest way would be. I've seen templates that help do some of the lifting but not much -- you still end up needing to write forwarding functions for every method of the class that you're trying to wrap. Is there an easier way?
I'm imagining a tool used as part of the make process. You want your public headers to be pimpl'd classes, so you provide some input file, say pimpl.in, that lists the classes (implemented un-pimpl'd) that you'd like to wrap, then that file is examined, the pimpl classes are generated and only their headers (not the original class's headers) are installed during a 'make install'. The problem is I don't see any way to do this without a full blown C++ parser, something even compiler vendors can't get right. Maybe the classes could be written in someway that makes the job of an external tool easier, but I'm sure I'd end up missing all sorts of corner cases (e.g. templated classes and/or templated member functions).
Any ideas? Has anyone else come with a solution for this problem already?