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: Tue, 30 Apr 2024 15:01:42 +0100
On Mon, Apr 29, 2024 at 2:13 PM Peter Bindels wrote:
>
> For the specific use case you propose, I would use something like
>
> std::map<std::string_view, bool(*)(bool)>
>
> which pretty much does what you would want it to. It takes the views and does not copy them, but does have a full std::string interface on top of it. It comes with the usual view caveats, you must ensure they will exist forever - but that seems to be the basis of your question, so I think it fits.
>
> Would this not solve the problem with C++17?


Yeah, using "string_view" here would have the benefit of not having to
define an equality operation using strcmp.

But maybe we need some sort of class that has the option of copying
the object, something like this:

    https://godbolt.org/z/rz6dfvGPo

Received on 2024-04-30 14:01:56