C++ Logo


Advanced search

Re: [std-proposals] Base class reflection

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Tue, 31 Jan 2023 21:24:10 +0000
On Tue, 31 Jan 2023, 20:27 Arthur O'Dwyer, <arthur.j.odwyer_at_[hidden]>

> On Tue, Jan 31, 2023 at 3:23 PM Billy Martin via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>> You can't do this because there isn't any code that knows both B and D at
>> compile time.
>> The case I'm thinking of involves some templated container that has an
>> object of type D. (Maybe it's a type erasure system, a smart pointer,
>> whatever). That container knows the type D because it was passed as a
>> template argument when it was instantiated with a brand new D object.
>> Somewhere else, some other code has a pointer B* and they want it to point
>> to this object, but they don't know what type D is (it might not even be
>> knowable until runtime).
> Can you please show some example code?

Yeah I'm not clear what you want to do. How will you search for B in the
bases of D if you don't know both B and D?

Your proposed trait doesn't help.

Just write the exact code you think you want to write, but pretend that
> `std::bases_of<T>::type` already exists. Show how you'll solve your problem
> using `std::bases_of<T>::type`.

No need to pretend, it already exists in GCC.

#include <tr2/type_traits>



Received on 2023-01-31 21:24:27