$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Danny Havenith (dh.boost_at_[hidden])
Date: 2008-06-22 09:25:50
Hello all,
I've encountered some behaviour of maps in both fusion and mpl that I 
did not expect, when inserting elements with the same key. Both 
libraries behave the same.
To illustrate, I wrote the code below (full source at the end of this 
post), where I create a map with a single element an then insert an 
element with the same key (int_<1>). I expected the size<> of the 
resulting map to be 1. Instead, the size is 2. (all on msvc9 and gcc 
4.1.2 (MinGW), boost 1.35 and svn_head)
-----------------------------------
typedef pair< int_<1>, vector< int>      > first_element;
typedef pair< int_<1>, vector< int, int> > second_element;
typedef map< first_element> first_map;
typedef insert< first_map, second_element>::type
  second_map;
// it prints "2", I expected "1".
std::cout << size< second_map>::type() << std::endl;
-----------------------------------
Generally, when I inspect the type of the resulting map after several 
inserts, I see that all inserted elements are still there.
What is wrong with the above code? What should I do if I wanted the 
original entry to be replaced with the new one?
Danny.
------source-------
#include <iostream>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/insert.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/count.hpp>
#include <boost/mpl/map.hpp>
#include <boost/fusion/include/map.hpp>
#include <boost/fusion/include/insert.hpp>
#include <boost/fusion/include/count.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <utility> // std::pair
//#define USE_FUSION
int main(int argc, char* argv[])
{
#ifdef USE_FUSION
  using namespace boost::fusion::result_of;
  using std::pair;
  using boost::fusion::vector;
  using boost::fusion::map;
#else
  using namespace boost::mpl;
#endif
  using boost::mpl::int_;
  typedef pair< int_<1>, vector< int>      > first_element;
  typedef pair< int_<1>, vector< int, int> > second_element;
  typedef map< first_element> first_map;
  typedef insert< first_map, end< first_map>::type, 
      second_element>::type second_map;
  std::cout << size< second_map>::type() << std::endl;
  return 0;
}