
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; }

"Peter Foelsche" <foelsche@sbcglobal.net> wrote in message news:im65n2$u72$1@dough.gmane.org... I wrote my own insert to overcome this problem. Extracting the elements, sorting them and then inserting them back. I think this should either be fixed or documented. Or maybe there should be some option to enable what I want to do. (Stupid "smart" formating coming from Windows Mail -- functionality to destroy all formating) template<typename T0, typename T1> struct compare { typedef typename boost::mpl::less< typename T0::first, typename T1::first
::type type;
}; template<typename MAP, typename VALUE> struct insert1 { typedef typename boost::mpl::key_type<MAP, VALUE>::type KEY; typedef typename boost::mpl::erase_key<MAP, KEY>::type MAP1; typedef typename boost::mpl::accumulate< MAP1, boost::mpl::vector<>, boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
::type VECTOR;
typedef typename boost::mpl::sort< typename boost::mpl::push_back< VECTOR, VALUE
::type,
compare<boost::mpl::_1, boost::mpl::_2>
::type SORTED;
typedef typename boost::mpl::accumulate< SORTED, boost::mpl::map<>, boost::mpl::insert<boost::mpl::_1, boost::mpl::_2>
::type type;
};

AMDG On 03/21/2011 07:26 AM, Peter Foelsche wrote:
"Peter Foelsche" <foelsche@sbcglobal.net> wrote in message news:im65n2$u72$1@dough.gmane.org... I wrote my own insert to overcome this problem.
Extracting the elements, sorting them and then inserting them back.
I think this should either be fixed or documented.
boost::is_same returns true when the two arguments are exactly the same type. MPL makes absolutely no guarantees about the exact types of sequences. In Christ, Steven Watanabe

On 03/20/11 19:21, Peter Foelsche wrote:
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.
IIRC, mpl uses mpl::equal(or some similar name) to test equality of associative sequences.
participants (3)
-
Larry Evans
-
Peter Foelsche
-
Steven Watanabe