C++ Logo

sg7

Advanced search

Re: [SG7] Update: P1240R2 — Scalable Reflection

From: Matus Chochlik <chochlik_at_[hidden]>
Date: Sat, 15 Jan 2022 20:56:09 +0100
Hi David,

On Sat, Jan 15, 2022 at 8:45 PM David Rector via SG7 <sg7_at_[hidden]>
wrote:

>
> Now suppose a user decides they want to interface with reflection in an
> object-oriented style:
> ```
> template<auto R>
> struct DeclWrapper {
> auto nextDecl() { return
> DeclWrapper <decltype(std::meta::get_next_decl(R))>{}; }
> auto prevDecl() {…}
> auto getParent() { … }
> …
> };
>
> #include … // lots of stuff, big translation unit
>
> int foo;
> constexpr auto foorefl = DeclWrapper <decltype(^foo)>()>();
> ```
>
> What happens when `foorefl` is instantiated?
>
> First each member of DeclWrapper<decltype(^foo)> must be instantiated,
> which means we have to instantiate each return type, each of which is a
> DeclWrapper, which itself has to be instantiated, …
>
> The chain reaction results in instantiations of DeclWrappers for *every
> single declaration in the translation unit*.
>

I have actually done something like that here:
https://github.com/matus-chochlik/mirror/blob/develop/include/mirror/metadata.hpp
and
https://github.com/matus-chochlik/mirror/blob/develop/include/mirror/registry.hpp

for debugging, in order to have a way to easily force the extraction of all
metadata and also to see the performance of such "chain reaction".

--Matus

Received on 2022-01-15 19:56:21