C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Chimeric Pointer

From: Gergely Nagy <gergely.nagy.alt_at_[hidden]>
Date: Fri, 25 Nov 2022 17:31:12 +0100
So here is the solution:

#include <bits/stdc++.h>
 struct A {
    void fn_a() {}};
 struct B {
    void fn_b() {}};
 struct C : A, B {
 };
 template<typename T, typename... Ts>
concept PointerInheritsFrom = std::is_pointer_v<T> &&
(std::is_base_of_v<Ts, std::remove_pointer_t<T>> && ...);
 void call_stuff(PointerInheritsFrom<A, B> auto p) {
    p->fn_a();
    p->fn_b();}
 int main() {
    C z;
    call_stuff(&z); }

I think this is what you are looking for.


On Fri, Nov 25, 2022, 16:29 Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
>
> On Friday, November 25, 2022, Jason McKesson via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> There seems to be a broad lack of understanding of what this feature
>> is doing, probably due to unfamiliarity with the way the wxWidgets
>> library uses base classes.
>>
>> wxWidgets uses multiple inheritance in a lot of cases. The two classes
>> in question, `wxControl` and `wxTextEntry` are both base classes. A
>> control that wants to have text entry functionality would inherit from
>> both, but it is also possible to have text entry objects that are not
>> controls and controls that don't have text entry functionality.
>>
>> The goal of the proposal is to be able to write a function that takes
>> a single pointer to any type which inherits from *two or more* base
>> classes. And then use that pointer to access any function which is
>> available from any of these base classes.
>
> <snip>
>
>
> Thanks James, you hit the nail on the head here. What you wrote is
> _exactly_ what I'm thinking.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-11-25 16:31:29