https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96088

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |---
             Status|RESOLVED                    |REOPENED

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to François Dumont from comment #1)
> In f2 you use insert(Pair&&) method so a temporary is generated but then
> moved into the container. In f1 we try to check for insertion before
> generating the value_type and to do so we use hash<std::string> that
> generates an additional temporary.

I think we're trying to be too clever. Trying to avoid creating temporaries
just makes things complicated and fragile, and it's buggy and rejects valid
code.

(In reply to Marc Glisse from comment #3)
> Indeed. If we want to, I think it is possible to add some overloads for when
> the argument is exactly const char* or string_view, which should remain
> conforming and provide a significant part of the benefits.

I think we should try to do this instead.

For the general case, we should just create a value_type and see if it should
be inserted. Trying to avoid that temporary causes too many bugs.

But when key_type is std::string, Hash is std::hash<std::string> and Eq is
std::equal_to<std::string>, we could internally use std::hash<std::string_view>
and std::equal_to<std::string_view> instead.

Reply via email to