C++ Logo

std-discussion

Advanced search

Re: A Idea: Friend with Conditions

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 21 Jun 2025 14:00:44 -0400
On Sat, Jun 21, 2025 at 11:46 AM Tiago Freire <tmiguelf_at_[hidden]> wrote:
>
> I'm not convinced about the particular syntax.
>
> But let's say we have the following:
>
> public(T, is_derived_from<T, unit_test>):
>
> now I don't need compromise the class in order to evaluate internal states in unit tests.

With reflection, won't tests be able to break encapsulation whenever they want?

> let's say that you have an interface class that interacts with "bar" like objects and "foo" type objects but I don't want "foo" to interact with "bar" interfaces and I don't want "bar" to interact with "foo" interfaces... this would be very useful.

It's not clear to me why this hypothetical interface class needs to be
able to access the private data of some unbounded set of `bar` and
`foo` "like objects".

Received on 2025-06-21 18:00:56