C++ Logo

sg7

Advanced search

Re: [SG7] Update: P1240R2 — Scalable Reflection

From: Daveed Vandevoorde <daveed_at_[hidden]>
Date: Tue, 18 Jan 2022 13:40:29 -0500
> On Jan 18, 2022, at 1:03 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
>
> Daveed Vandevoorde wrote:
>>> On Jan 18, 2022, at 11:53 AM, Peter Dimov via SG7 <sg7_at_[hidden]>
>> wrote:
>>>
>>>> Daveed Vandevoorde wrote:
>>>>> — The proposed metafunctions now use span and string_view instead
>>>> of
>>>>> vector and string
>>>>
>>>> NTCS please :-(
>>>
>>> I'm serious. Please provide a way to obtain a `char const*` instead of
>>> std::string_view; that could take the form of a consteval magic
>>> function taking the std::string_view returned from the official API.
>>>
>>> Since the compiler will not want to be married to a particular stdlib,
>>> its internal primitives are not going to be creating std::string_views
>>> anyway.
>>
>>
>> I missed this before. We could return a NTCS instead: Would that be more
>> usable? It’s certainly easier to implement.
>
> It's unfortunately not more usable. With a string_view, you can write
> `name_of(x) == "f"` and have it work correctly.
>
> But on the other hand, if you have a `char const*`, it's trivial to obtain a
> string_view from it, whereas the reverse... isn't.
>
> So I can't with a clear conscience insist on changing the API to return
> `char const*` because this degrades usability for simple things (even if
> that doesn't occur very often outside of toy examples), but I would very
> much like _some_ way of obtaining a `char const*`.


How about specifying that all string_view results from reflection functions (there aren’t that many) have a null-terminated data()?
E,g,:

 auto len = std::strlen(name_of(^S).data()); // Okay and as intuitively expected.

 Daveed


Received on 2022-01-18 18:40:30