Opened 8 years ago

Last modified 7 years ago

#10071 new Bugs

[container] flat_map::insert() is ambiguous if used with initializer lists

Reported by: Sebastian Karlsson <sebastian@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

boost::container::flat_map< unsigned int, unsigned int > foo; foo.insert( { 1u, 1u } );

Doesn't fly, since it can either convert to std::pair<> or boost::container_detail::pair<>.

Change History (4)

comment:1 by Ion Gaztañaga, 8 years ago

Merging issue #10135. Copying the issue text:

[container] flat_map::insert() is ambiguous if used with pair that requires conversion

Reported by: Sebastian Karlsson Version: Boost 1.55.0

The following is a no go it seems:

boost::container::flat_map< int, int > fm; fm.insert( std::make_pair( 0u, 0 ) );

Because the pair has to be converted, but it can be converted to either std::pair<> or container::container_details::pair<>.

comment:2 by Ion Gaztañaga, 8 years ago

Fixing this correctly requires a bit of surgery since it should avoid using boost::container::container_detail::pair and make std::pair moveable on compilers without movable std::pair. As a first step, in compilers with rvalue reference we could avoid boost::container::container_detail::pair but we shouldn't break old code.

comment:3 by viboes, 7 years ago

What is wrong documenting the limitation on c++03 and requesting the user to use boost::make_pair?

comment:4 by anonymous, 7 years ago

As a first-time user of flat_map, I was pretty confused why

insert( std::make_pair( x, y ) )

wasn't compiling, especially since the docs suggest that the Boost containers are drop-in replacements, and since flat_map::value_type is std::pair. At any rate, I just recommend including a note on proper usage in the descriptions for the insert() family.

P.S. For anybody stumbling across this bug report after a Google search, you can use

emplace( std::make_pair(x, y ) )

Still not { x, y }, though.

Note: See TracTickets for help on using tickets.