Boost C++ Libraries: Ticket #10071: [container] flat_map::insert() is ambiguous if used with initializer lists https://svn.boost.org/trac10/ticket/10071 <p> boost::container::flat_map&lt; unsigned int, unsigned int &gt; foo; foo.insert( { 1u, 1u } ); </p> <p> Doesn't fly, since it can either convert to std::pair&lt;&gt; or boost::container_detail::pair&lt;&gt;. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10071 Trac 1.4.3 Ion GaztaƱaga Mon, 23 Jun 2014 20:58:44 GMT <link>https://svn.boost.org/trac10/ticket/10071#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10071#comment:1</guid> <description> <p> Merging issue <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10135" title="#10135: Bugs: [container] flat_map::insert() is ambiguous if used with pair that ... (closed: duplicate)">#10135</a>. Copying the issue text: </p> <p> [container] flat_map::insert() is ambiguous if used with pair that requires conversion </p> <p> Reported by: Sebastian Karlsson Version: Boost 1.55.0 </p> <p> The following is a no go it seems: </p> <div class="wiki-code"><div class="code"><pre><span class="n">boost</span><span class="o">::</span><span class="n">container</span><span class="o">::</span><span class="n">flat_map</span><span class="o">&lt;</span> <span class="kt">int</span><span class="p">,</span> <span class="kt">int</span> <span class="o">&gt;</span> <span class="n">fm</span><span class="p">;</span> <span class="n">fm</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span> <span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span> <span class="mi">0u</span><span class="p">,</span> <span class="mi">0</span> <span class="p">)</span> <span class="p">);</span> </pre></div></div><p> Because the pair has to be converted, but it can be converted to either std::pair&lt;&gt; or container::container_details::pair&lt;&gt;. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion GaztaƱaga</dc:creator> <pubDate>Mon, 23 Jun 2014 21:22:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10071#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10071#comment:2</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 06 Dec 2015 09:11:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10071#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10071#comment:3</guid> <description> <p> What is wrong documenting the limitation on c++03 and requesting the user to use boost::make_pair? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 09 Jan 2016 18:35:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10071#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10071#comment:4</guid> <description> <p> As a first-time user of flat_map, I was pretty confused why </p> <div class="wiki-code"><div class="code"><pre><span class="n">insert</span><span class="p">(</span> <span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="p">)</span> <span class="p">)</span> </pre></div></div><p> 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> <p> P.S. For anybody stumbling across this bug report after a Google search, you can use </p> <div class="wiki-code"><div class="code"><pre><span class="n">emplace</span><span class="p">(</span> <span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="p">)</span> <span class="p">)</span> </pre></div></div><p> Still not { x, y }, though. </p> </description> <category>Ticket</category> </item> </channel> </rss>