Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2007-03-22 10:43:50


on Thu Mar 22 2007, Scott Meyers <usenet-AT-aristeia.com> wrote:

> I expect the following code to compile cleanly. It does not.
>
> #include <boost/mpl/set.hpp>
> #include <boost/mpl/equal.hpp>
> #include <boost/mpl/erase_key.hpp>
>
> namespace mpl = boost::mpl;
> using mpl::_1;
> using mpl::_2;
>
> struct A {};
> struct B {};
>
> typedef mpl::set<A, B> set1;
> typedef mpl::set<B, A> set2;
>
> BOOST_MPL_ASSERT((
> mpl::equal<
> mpl::erase_key<set1, A>::type,
> mpl::erase_key<set2, A>::type
> >
> ));
>
> I'm simply trying to assert that the sets {A,B} and {B,A} have the same
> elements after A has been removed from both. What am I doing wrong?

Nothing; this is clearly a bug in MPL, better demonstrated by:

  #include <boost/mpl/set.hpp>
  #include <boost/mpl/equal.hpp>
  #include <boost/mpl/erase_key.hpp>

  namespace mpl = boost::mpl;

  struct A {};
  struct B {};

  typedef mpl::set<A, B> ab_set;

  typedef mpl::erase_key<ab_set, A>::type b_set;

  BOOST_MPL_ASSERT((
       boost::is_same<
           mpl::deref<
               mpl::begin<b_set>::type
>::type
         , B
>));

which yields:

  fu.cpp:17: error: No match for ‘assertion_failed(
        mpl_::failed ************ boost::is_same<
            boost::mpl::set2<A, B>
          , B>::************)’

In other words, erasing A from set<A,B> results in a sequence whose
first element is set2<A,B>. I'll have to defer to Aleksey at this
point, since he is the implementor. Aleksey?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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