C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function only accepts parameter that will persist

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 6 May 2024 20:15:18 +0100
On Mon, May 6, 2024 at 7:18 PM Thiago Macieira wrote:
>
> There's no such thing as a pointer-or-reference to static-storage only in the
> core language. I can find a couple of use-cases for that, usually related to
> strings, but they're few. Most of those can also be worked around by simply
> documenting the expectation.
>
> Adding such a type would be a major core language update.


Okay then if it's too much grief to make a major core language update
to add a new type modifier, then how about just standardising a new
operator called:

      _Is_referent_constexpr

which could be used as follows:

    template<size_t n>
    constexpr std::efficient_string::efficient_string(char const (&arg)[n])
    {
        if consteval
        {
            if ( _Is_referent_constexpr(arg) )
            {
                DontCopyTheString();
                return;
            }
        }

        CopyTheString();
    }

Received on 2024-05-06 19:15:24