Boost logo

Boost Users :

Subject: [Boost-users] mpl and set of maps
From: Peter Foelsche (foelsche_at_[hidden])
Date: 2011-03-20 20:21:42


It looks like two maps with the same entries but different ordering are
considered different.
I'm trying to create a set of maps and I'm inserting two maps.
Both maps are identical but the order in which the items were inserted into
the map is different.
I was thinking that an associative sequence like set is using is_same to
compare two elements
and I tried to overload is_same -- but this did not work.
See code below or attached.

#include <boost/mpl/set.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/long.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/insert.hpp>
#include <iostream>
?
struct print
{ template<typename T>
void operator()(const T &_r) const
{ //std::cout << typeid(T).name() << "\n";
(*this)(_r, typename boost::mpl::is_sequence<T>::type());
}
template<typename T>
void operator()(const T &, const boost::mpl::true_ &) const
{ std::cout << "(\n";
boost::mpl::for_each<T>(print());
std::cout << ")\n";
}
template<typename T0, typename T1>
void operator()(const boost::mpl::pair<T0, T1> &, const boost::mpl::false_
&) const
{ std::cout << "pair(" << typeid(T0).name() << ", " << typeid(T1).name() <<
")" << "\n";
}
template<typename T>
void operator()(const T &, const boost::mpl::false_ &) const
{ std::cout << typeid(T).name() << "\n";
}
};
namespace boost
{
//namespace type_traits
//{
//template<typename T0, typename T1>
//struct is_same;
?
using boost::mpl::map;
using boost::mpl::true_;
using boost::mpl::insert;
?
template<typename T0, typename T1>
struct is_same<map<T0, T1>, map<T1, T0> >
{ typedef boost::mpl::true_ type;
};
?
template<typename T0, typename T1, typename T2>
struct is_same<map<T0, T1, T2>, map<T2, T1, T0> >
{ typedef boost::mpl::true_ type;
};
?
template<typename T0, typename T1, typename T2>
struct is_same<map<T0, T1, T2>, map<T1, T2, T0> >
{ typedef boost::mpl::true_ type;
};
?
template<typename T0, typename T1, typename T2>
struct is_same<map<T0, T1, T2>, map<T0, T2, T1> >
{ typedef boost::mpl::true_ type;
};
?
template<typename T0, typename T1, typename T2>
struct is_same<map<T0, T1, T2>, map<T1, T0, T2> >
{ typedef boost::mpl::true_ type;
};
//}
}
int main(int argc, char **argv)
{
using boost::mpl::long_;
using boost::mpl::for_each;
using boost::mpl::set;
using boost::mpl::map;
using boost::mpl::pair;
using boost::mpl::insert;
typedef long_<0> zero;
typedef long_<1> one;
typedef long_<2> two;
typedef pair<
zero,
one
> zero_2_one;
typedef pair<
one,
one
> one_2_one;
for_each<
insert<
insert<
set<>,
insert<
insert<
map<>,
zero_2_one
>::type,
one_2_one
>::type
>::type,
insert<
insert<
map<>,
one_2_one
>::type,
zero_2_one
>::type
>::type
>(print());
return 0;
}




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net