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@lists.isocpp.org> wrote:
On Sun, Nov 27, 2022 at 10:19 PM Frederick Virchanza Gotham
<cauldwell.thomas@gmail.com> 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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals