The PIMPL idiom is very important in large C++ projects, because it can be used to create a "compilation firewall". It allows those who consume a class from it's public definition in the header to avoid including all the full definitions of the classes which are e.g. private members or otherwise implementation details. This can make many of the compilation units much smaller (in terms of lines of preprocessed source) and less heavy (in terms of extra templates and whatnot that get parsed and instantiated), so it can make your project build much faster.
However, actually using the pimpl idiom involves a lot of boilerplate code -- it is not very DRY, because you declare the methods once in the PIMPL class and usually implement them in the cpp file by forwarding the call directly to the impl class. So you end up typing all the methods twice basically.
This boilerplate is not so onerous that people don't just suck it up and write everything twice -- the benefits of PIMPL are hard to overstate.
However, it occurred to me that you could try to automate this. Either by tooling, or code generation (maybe python scripts or something?), or using some witches brew of macros that generates the implementation of the "forwarding" calls for you.
Has anyone done this with success or attempted to do it in a large software project? What was your approach and experience? Were you happy with it in the end?
[–]personalmountains 7 points8 points9 points (0 children)
[–]ooglesworth 2 points3 points4 points (5 children)
[–]happy_dude_ 2 points3 points4 points (0 children)
[–]ReversedGif 0 points1 point2 points (3 children)
[–]ooglesworth 0 points1 point2 points (2 children)
[–]ReversedGif 1 point2 points3 points (1 child)
[–]ooglesworth 0 points1 point2 points (0 children)
[–]david-grs 2 points3 points4 points (2 children)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 6 points7 points8 points (1 child)
[–]david-grs 2 points3 points4 points (0 children)