Opened 9 years ago

Last modified 8 years ago

#8749 new Bugs

Accessing type of insert<map<>, pair<A,B> >::type discards inserted elements

Reported by: guylaingreer@… Owned by: Aleksey Gurtovoy
Milestone: To Be Determined Component: mpl
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc:

Description

The following code sample illustrates the problem

typedef insert<map<>, pair<int, int> >::type little_map;

BOOST_STATIC_ASSERT(size<little_map>::value == 1); /* Success */ BOOST_STATIC_ASSERT(size<little_map::type>::value == 1); /* Failure */

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<...> 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.

The solution, quite staightforwardly is to simply add the line "typedef m_item type;" to the class' definition.

It should be noted that I am running version 1.48 of Boost, but have checked http://www.boost.org/doc/libs/1_52_0/boost/mpl/map/aux_/item.hpp 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.

Change History (3)

comment:1 by anonymous, 8 years ago

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..

typedef lambda<
    eval_if<
        has_key<_1, key_type<_1, _2>>,
        identity<_1>,
        insert<_1, _2>
    >
>::type insert_if_new;

Which, based on the docs I have read, should clearly work, but it fails without the typedef above. This is on 1.56

comment:2 by brunocodutra@…, 8 years ago

Duplicate of [Ticket #7975].

comment:2 by brunocodutra@…, 8 years ago

Duplicate of #7975

Note: See TracTickets for help on using tickets.