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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Antonio Di Monaco from comment #2)
> Well, I tried, but nothing changes.
> 
>   assert(a.insert(std::make_pair< const int, int >(1, 1)).second);
>   assert(a.insert(std::make_pair< const int, int >(2, 2)).second);
>   assert(!a.insert(std::make_pair< const int, int >(1, 3)).second);
> 
> still allocates three times, while GCC6 two times.

Because make_pair<const int, int>(1, 2) still returns pair<int, int>, so you're
still not inserting the value_type.

(Using make_pair with an explicit template argument list is dumb, the whole
point is to deduce the argument types so if you specify the types there's no
deduction and no point using make_pair.)


> Even changing K to const int in the map does not produce any different
> behavior.

Because that doesn't change anything either.

The value type is still pair<const int, int> either way, and you're still
inserting pair<int, int>.

This inserts the correct value type, and doesn't perform an addition
allocation:

  assert(a.insert(std::pair<const int, int>(1, 1)).second);
  assert(a.insert(std::pair<const int, int>(2, 2)).second);
  assert(!a.insert(std::pair<const int, int>(1, 3)).second);

Reply via email to