|
Boost : |
From: Gavin Lambert (boost_at_[hidden])
Date: 2023-02-06 23:21:44
On 6/02/2023 22:22, Hans Dembinski wrote:
> Hubert Liberacki wrote this library
>
> https://github.com/hliberacki/cpp-member-accessor
>
> that uses a loophole in the C++ standard which allows one to access
> private members and methods in classes in external libraries that are
> not under the control of the library author. Since the loophole is
> legal, it works with all major compilers and on all platforms. No
> special compiler flags required nor illegal macros like #define
> private public.
Interesting; I was aware of the technique and have used it in a couple
of places where it was needed, but was not aware of this library.
> I think this should be integrated in Boost, is there interest other
> from myself?
Is there interest from the library author in so integrating it?
Certainly Boost shouldn't be in the business of integrating external
libraries without enthusiastic support from their original author.
> Before you say it is evil, consider all the good that can be done
> with this in responsible hands. You can add serialisation support to
> classes that you do not control and you can write efficient Python
> bindings. I have used this library now in three projects. I used it
> to add serialisation support and to provide memory views of C++
> structures in Python (via the Numpy module), both wouldn't have been
> possible to do or not would not have been efficient without this.
I do worry that making the technique too easily accessible might
encourage abuse, though. Even external serialization should ordinarily
be accomplished via public members where possible; it's too easy to
create brittle code when using private members in the presence of any
library upgrades (or library version abstraction as common in
package-management systems) or polymorphism.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk