C++ Logo


Advanced search

Re: [std-proposals] Chimeric Pointer (template param id's)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 28 Nov 2022 09:17:46 +0000
On Sun, Nov 27, 2022 at 10:19 PM Frederick Virchanza Gotham
<cauldwell.thomas_at_[hidden]> wrote:
> 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;

As a stepping-stone to making something like the above possible, what
if we could give arbitrary words (or arbitrary identifiers) as
template parameters? Something like as follows:

        template<identifier K, class T>
        constexpr auto GetMemberAddress(T const &t)
            return &T::K;

So then we could do:

        #include <string>

        int main(void)
            std::string str;

           auto f = GetMemberAddress<"size">(str);

           return (str.*f)();

Has there ever been any talk about allowing arbitrary
strings/words/identifiers as template parameters?

Received on 2022-11-28 09:17:56