C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Method/member granular friendship

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Mon, 11 Nov 2024 12:47:44 +0100
Hi Francesco,   is your intention to improve the code (by limiting visibility or access) within your library or the outside interface.   Problem: "within the library compilation boundaries, some classes tend to loose proper encapsulation" Solution B: "or (if it makes any sense at all) having an equivalent C++ module visibility modifier"   Does your library comprise different (intended/possible) modules? And the current friendships span those boundaries and should be reduced? (Many small libraries would perhaps be just one module.)   If you would not use several modules for the one library, then some existing or new access or visibility controls by module granularity would not help in your case.   If yes, can you make a concrete (mock) example of classes within different module scopes being friends, but only for some members?   Solution A: For the more granular friends approach without modules, this discussion could be interesting: https://groups.google.com/a/isocpp.org/g/std-proposals/c/wtkDvujmjug "Improving Friends with Attributes" Sadly the paper seems to be not available anymore at the old location.   Best, Sebastian     -----Ursprüngliche Nachricht----- Von:Francesco Pretto via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mo 11.11.2024 10:36 Betreff:[std-proposals] Method/member granular friendship An:std-proposals_at_[hidden]; CC:Francesco Pretto <ceztko_at_[hidden]>; Hello, I'm the maintainer of a modern C++ library that evolved from a C++98 legacy code base. Inspired by a trend which is very frequent in Microsoft .NET base class library (where, to prevent bogus inheritance, many classes are either final or provide inaccessible constructors), I decided to perform an extensive API surface reduction of the whole library. This involved making heavy use of class friendship in C++ to the point that, within the library compilation boundaries, some classes tend to loose proper encapsulation. In .NET/C#, this is solved by the member "internal" visibility modifier, which makes certain methods/fields to be accessible only within an assembly (aka module) boundary. In C++ this could be solved by either introducing a method/member granular friendship or (if it makes any sense at all) having an equivalent C++ module visibility modifier. Is there any proposal to add one of the two? Or am I missing something already existing in the language? I'm not interested in solving the issue through code patterns. Regards, Francesco -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-11-11 11:48:38