C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow conversion of memfunc pointers to func pointers

From: Jarrad Waterloo <descender76_at_[hidden]>
Date: Tue, 16 Jan 2024 07:58:27 -0500
Frederick,




*I wonder if there will come a point when we should mention vtables inthe
Standard? We don't have to call them vtables, maybe just call
them"polymorphic facilitators" or some other generic term that leaves
thedoor open for compiler implementers, and then we could ...*

>From the references of
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2603r1.html
https://github.com/boost-ext/te
https://github.com/ldionne/dyno

others include
https://github.com/iboB/dynamix
http://www.boost.org/doc/libs/release/doc/html/boost_typeerasure.html
https://github.com/facebook/folly/blob/master/folly/docs/Poly.md

This has gone back in standard discussions for decades:

This is far from a comprehensive list:
Proxy: A Polymorphic Programming Library
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0957r9.pdf
Language support for customisable functions
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2547r0.pdf

Runtime Concepts
https://stlab.cc/legacy/runtime-concepts.html
Runtime Concepts for the C++ Standard Template Library
https://www.stroustrup.com/oops08.pdf

https://github.com/andyprowl/virtual-concepts


















On Tue, Jan 16, 2024 at 2:45 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:

> On Mon, Jan 15, 2024 at 1:57 AM Thiago Macieira via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> > then the vtable linker symbol is
> > > '_ZTV5Donkey'.
> >
> > And this one is _ZTV6Donkey.
>
>
> Another possibility would be to get the vtable pointer from the
> 'std::type_info', as follows:
>
> template<class Class> requires std::is_polymorphic_v<Class>
> void (*const *GetVtable(void))(void)
> {
> // The type_info struct for T is located
> // right after the vtable for T.
> // The vtable for T contains a pointer to the type_info.
> // So take the address of the type_info struct,
> // and keep decrementing and dereferencing it until we
> // see the address of the type_info struct -- the vtable
> // is right after it.
>
> static constexpr void const *pv = &typeid(Class);
> static constexpr void const *const *ppv = static_cast<void
> const *const *>(pv);
>
> for ( void const *const *p = ppv; ; --p )
> {
> if ( pv != *p ) continue;
>
> return
> static_cast<void(*const*)(void)>(
> static_cast<void const*>(
> static_cast<char const*>(
> static_cast<void const*>(p)
> ) - 0xe8
> )
> );
> }
> }
>
> I have it working here: https://godbolt.org/z/fe9Wd5EW1
>
> I wonder if there will come a point when we should mention vtables in
> the Standard? We don't have to call them vtables, maybe just call them
> "polymorphic facilitators" or some other generic term that leaves the
> door open for compiler implementers, and then we could get the vtable
> pointer from the 'type_info' as follows:
>
> namespace std {
> class type_info {
> void const *get_polymorphic_facilitator(void) noexcept;
> };
> }
>
> Let it return a nullptr if !std::is_polymorpic_v<T>.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-01-16 12:58:41