C++ Logo


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:59:58 -0400
> On Apr 9, 2021, at 10:56 AM, Peter Dimov <pdimov_at_[hidden]> wrote:
> David Vandevoorde wrote:
>> 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.
> Bounds-wise `char const*` and string_view are basically equivalent because
> in either case the length is a constant expression.

When I said “performance win”, I meant “compile-time performance” ;-)

I.e., we can avoid evaluation loop at compile-time. The win might not be significant (or it might even be a slight loss) if the length is computed using an intrinsic though.


> I did get a request for
> char const[] though, instead of char const*. I'm reluctant to switch to that
> because I'm afraid it may introduce the same problems __func__ had.

Received on 2021-04-09 10:00:10