C++ Logo

sg7

Advanced search

Re: Update: P1240R2 — Scalable Reflection - Clarifications

From: Peter Dimov <pdimov_at_[hidden]>
Date: Mon, 31 Jan 2022 19:08:15 +0200
Daveed Vandevoorde wrote:
> > This reminds me of an observation I had: it would have been nice if we
> > could actually form pointer to member to a specific base class, so
> > that we can then reflect it.
>
> I can see how that could be useful: Extend the notion of pointer-to-member to
> also be able to designate bases.
>
> (That’s orthogonal to reflection though.)
>
>
> > Because as-is, if you have two bases of the same type, there's no way
> > you can differentiate between them just by their type.
>
> Even “not as is”: It’s an ambiguous question to ask?

It's not ambiguous if you have reflection information.

In Boost.Describe, I support a "modifier" mod_inherited, which includes the
inherited members in the "members_of" list. I don't currently support it for
the base classes, but I could. So when you have

struct B {};
struct D1: B {};
struct D2: B {};
struct C: D1, D2 {};

and you say describe_bases<C, mod_any_access | mod_inherited>, you would
get a list of base class descriptors [desc(D1), desc(B), desc(D2), desc(B)]. So you
have two descriptors about a base class of type B, but they refer to different
bases. And if the base class descriptor contained a member pointer to the base,
like data member descriptors contain a member pointer to the data member,
you would be able to go from C* to the first B* using the first pointer, and to
the second B* using the second pointer.

Not sure if this makes any sense. :-) I hope it does.

Received on 2022-01-31 17:08:17