C++ Logo

std-proposals

Advanced search

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

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Mon, 28 Nov 2022 10:50:44 +0100
Hi,

I think some of the compile time reflection proposals cover this. I don't think you need anything special about the template parameter. It can be a structural type that can be initialised from a string literal. The magic is in looking up a member from that compile-time string.

Cheers,
Lénárd

On 28 November 2022 10:17:46 CET, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>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;
><snip>
>
>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?
>--
>Std-Proposals mailing list
>Std-Proposals_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-11-28 09:50:52