C++ Logo

SG7

Advanced search

Subject: Re: Reason for members of namespace
From: Zach Laine (whatwasthataddress_at_[hidden])
Date: 2020-11-03 11:19:13


@Cleiton The take-away is: resolve all these questions to EWG's
satisfaction, and you might just get this. It is widely desired, but
the issues are real, as Andrew noted.

Zach

On Tue, Nov 3, 2020 at 7:58 AM Andrew Sutton via SG7
<sg7_at_[hidden]> wrote:
>>
>> "Of note here is that we are not proposing a function to retrieve members of namespaces..."
>>
>> I believe "Automatic Class Register" for load/storing frameworks, may be a good reason for members of namespace ( obviously filtered ):
>>
>> I need to get all classes derived from "Widget" (called T in this sample) in the namespace "MyFramework" and all of it´s inner namespaces, that has funcion "toStream(ostream&)" declared.
>
>
> I also have good uses cases for getting namespace members. The reason we avoided doing it in P1240 is largely due to technical reasons. For example:
>
> namespace N {
> void f();
> void f();
> }
>
> static_assert(members_of(reflexpr(N) == 2); // error or OK?
>
> In Clang, the answer is 2. In GCC, the answer is 1. Which is right? P2237 actually discusses this particular issue: the answer will be 1 because you have two declarations of the same entity.
>
> Reopening namespaces also poses some interesting issues:
>
> namespane N { void f(); }
> static_assert(members_of(reflexpr(N) == 1);
> namespane N { void g(); }
> static_assert(members_of(reflexpr(N) == 2); // huh
>
> Despite being a constexpr function, members_of returns non-equal values at different points in the program. Some people tend to be leery about constexpr functions returning different values depending on where they're called---they aren't really constant expressions anymore. This would break an implementation that tries to cache results.
>
> And then there are some sticky questions about how to reflect unnamed namespaces, using directives, using namespace directives, etc.
>
> --
> SG7 mailing list
> SG7_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg7


SG7 list run by sg7-owner@lists.isocpp.org

Older Archives on Google Groups