C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Chimeric Pointer

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 27 Nov 2022 22:19:46 +0000
On Sun, Nov 27, 2022 at 5:03 PM Phil Endecott via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> I think it would be possible to implement operator->* to make this possible:

I have a half-baked idea in my head but I'm trying to get the
following to somehow work to achieve automatic lookup of the member
object/function:

#include <cstddef>
#include <tuple>

template<std::size_t n, class... ParamPack>
using Nth = std::tuple_element_t< n, std::tuple<ParamPack...> >;

template<class... Bases>
auto close(void)
{
         if constexpr (requires { &Nth< 0u,Bases...>::close; }) return
&Nth< 0u,Bases...>::close;
    else if constexpr (requires { &Nth< 1u,Bases...>::close; }) return
&Nth< 1u,Bases...>::close;
    else if constexpr (requires { &Nth< 2u,Bases...>::close; }) return
&Nth< 2u,Bases...>::close;
    else if constexpr (requires { &Nth< 3u,Bases...>::close; }) return
&Nth< 3u,Bases...>::close;
    else if constexpr (requires { &Nth< 4u,Bases...>::close; }) return
&Nth< 4u,Bases...>::close;
    else if constexpr (requires { &Nth< 5u,Bases...>::close; }) return
&Nth< 5u,Bases...>::close;
    else if constexpr (requires { &Nth< 6u,Bases...>::close; }) return
&Nth< 6u,Bases...>::close;
    else if constexpr (requires { &Nth< 7u,Bases...>::close; }) return
&Nth< 7u,Bases...>::close;
    else if constexpr (requires { &Nth< 8u,Bases...>::close; }) return
&Nth< 8u,Bases...>::close;
    else if constexpr (requires { &Nth< 9u,Bases...>::close; }) return
&Nth< 9u,Bases...>::close;
    else if constexpr (requires { &Nth<10u,Bases...>::close; }) return
&Nth<10u,Bases...>::close;
    else if constexpr (requires { &Nth<11u,Bases...>::close; }) return
&Nth<11u,Bases...>::close;
    else if constexpr (requires { &Nth<12u,Bases...>::close; }) return
&Nth<12u,Bases...>::close;
    else if constexpr (requires { &Nth<13u,Bases...>::close; }) return
&Nth<13u,Bases...>::close;
    else if constexpr (requires { &Nth<14u,Bases...>::close; }) return
&Nth<14u,Bases...>::close;
    else if constexpr (requires { &Nth<15u,Bases...>::close; }) return
&Nth<15u,Bases...>::close;
}

I'm not sure what I'm thinking or what I'm trying to do, but it came
into my head to try mess with the above.

Received on 2022-11-27 22:19:56