C++ Logo

SG7

Advanced search

Subject: Re: string. vector vs string_view, span in reflection API
From: David Vandevoorde (daveed_at_[hidden])
Date: 2021-04-09 09:59:58


> 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.

        Daveed

> 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.
>


SG7 list run by sg7-owner@lists.isocpp.org

Older Archives on Google Groups