Boost C++ Libraries: Ticket #8749: Accessing type of insert<map<>, pair<A,B> >::type discards inserted elements https://svn.boost.org/trac10/ticket/8749 <p> The following code sample illustrates the problem </p> <blockquote> <p> typedef insert&lt;map&lt;&gt;, pair&lt;int, int&gt; &gt;::type little_map; </p> </blockquote> <blockquote> <p> BOOST_STATIC_ASSERT(size&lt;little_map&gt;::value == 1); /* Success */ BOOST_STATIC_ASSERT(size&lt;little_map::type&gt;::value == 1); /* Failure */ </p> </blockquote> <p> I have traced the problem to the file boost/mpl/map/aux_/item.hpp in the class definition of m_item. m_item derives from Base (which is a map&lt;...&gt; type) but does not define a "typedef m_item type;" to act as a unary metafunction returning itself. The result is that Base::type is found instead which means that m_item acts as a unary metafunction returning a map with all the inserted elements removed. The class m_item_ at the bottom of the file properly defines a "typedef m_item_ type;" which strengthens my belief that it missing from m_item is a bug. </p> <p> The solution, quite staightforwardly is to simply add the line "typedef m_item type;" to the class' definition. </p> <p> It should be noted that I am running version 1.48 of Boost, but have checked <a href="http://www.boost.org/doc/libs/1_52_0/boost/mpl/map/aux_/item.hpp">http://www.boost.org/doc/libs/1_52_0/boost/mpl/map/aux_/item.hpp</a> and it still lacks the define so I'm convinced that this problem will still be there when I download the latest version of boost. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8749 Trac 1.4.3 anonymous Tue, 14 Oct 2014 15:51:57 GMT <link>https://svn.boost.org/trac10/ticket/8749#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8749#comment:1</guid> <description> <p> This bug just bit me as well. I'm just learning MPL, so maybe this isn't the best way, but I was writing a little map insertion lambda.. </p> <pre class="wiki">typedef lambda&lt; eval_if&lt; has_key&lt;_1, key_type&lt;_1, _2&gt;&gt;, identity&lt;_1&gt;, insert&lt;_1, _2&gt; &gt; &gt;::type insert_if_new; </pre><p> Which, based on the docs I have read, should clearly work, but it fails without the typedef above. This is on 1.56 </p> </description> <category>Ticket</category> </item> <item> <author>brunocodutra@…</author> <pubDate>Sat, 21 Feb 2015 22:18:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8749#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8749#comment:2</guid> <description> <p> Duplicate of [Ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/7975" title="#7975: Bugs: mpl::insert&lt;...&gt;::type::type returns empty map when inserting into an ... (new)">#7975</a>]. </p> </description> <category>Ticket</category> </item> <item> <author>brunocodutra@…</author> <pubDate>Sat, 21 Feb 2015 22:19:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8749#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8749#comment:2</guid> <description> <p> Duplicate of <a class="new ticket" href="https://svn.boost.org/trac10/ticket/7975" title="#7975: Bugs: mpl::insert&lt;...&gt;::type::type returns empty map when inserting into an ... (new)">#7975</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>