C++ Logo

sg7

Advanced search

Re: [SG7] string. vector vs string_view, span in reflection API

From: David Vandevoorde <daveed_at_[hidden]>
Date: Fri, 9 Apr 2021 10:46:40 -0400
> On Apr 9, 2021, at 10:26 AM, Peter Dimov <pdimov_at_[hidden]> wrote:
>
> David Vandevoorde wrote:
>> One of the issues that arise is header dependencies… do we really want to
>> require that <vector> and <string> be included for any code that does
>> something nontrivial with reflections? Maybe “yes”, and maybe that’ll be less
>> of a concern with modules?
>>
>> Meanwhile, our (Faisal & I) current implementation uses std::string_view (with
>> some assumptions about its internal structure) and a very simple
>> vector<info>-like class that’s part of the <meta> header.
>
> That's another reason I prefer `char const*` - I don't find it elegant when
> compiler built-ins have to know about user-defined types such as `string_view`.

Implementation-wise it’s not as elegant, but I suspect programmers might like it better on average. It’s also potentially a performance win, because at the time we create the string_view, we know the bounds of the array. If we return it as a char const*, you’d have to recover that.

(Our assumptions are that string_view is either a “start” pointer and a length (in any order) or a “start” pointer followed by an “end” pointer.)

 Daveed

Received on 2021-04-09 09:46:47