C++ Logo

sg7

Advanced search

Re: [SG7] Update: P1240R2 — Scalable Reflection

From: Daveed Vandevoorde <daveed_at_[hidden]>
Date: Tue, 18 Jan 2022 14:27:38 -0500
> On Jan 18, 2022, at 2:16 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
>
> Daveed Vandevoorde wrote:
>>> On Jan 18, 2022, at 1:46 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
>>>
>>> Daveed Vandevoorde wrote:
>>>> 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.
>>>
>>> Works for me, with the minor addition of `constexpr` before `auto len`.
>>
>> Can you elaborate on the minor addition? Are you just asking for std::strlen to
>> be guaranteed evaluatable at compile time for strings?
>
> For the specific strings obtained by some_reflection_function().data(), yes.
>
> constexpr auto len = std::strlen(name_of(^S).data());

That seems reasonable, but it feels a bit orthogonal to P1240. I.e., it would be weird if those were the _only_ strings for which that worked.

Presumably, it should work for any core-constant null-terminated char array?

 Daveed


Received on 2022-01-18 19:27:40