[mpl] erase_key confusion

I expect the following code to compile cleanly. It does not.
#include
)); 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? Thanks, Scott

on Thu Mar 22 2007, Scott Meyers
I expect the following code to compile cleanly. It does not.
#include
#include #include namespace mpl = boost::mpl; using mpl::_1; using mpl::_2;
struct A {}; struct B {};
typedef mpl::set set1; typedef mpl::set set2;
BOOST_MPL_ASSERT(( mpl::equal< mpl::erase_key
::type, mpl::erase_key ::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

David Abrahams wrote:
Nothing; this is clearly a bug in MPL
As a workaround, I thought I'd write an erase_first function as shown
below, but this seems to have the same problem. Perhaps this is because
I'm using erase in my implementation, and erase_key may, I suppose, be
implemented on top of erase. More likely, I'm doing something wrong.
More likely still, the way I'm doing it is gross. I'd appreciate
feedback on the implementation of my erase_first function, where I've
put comments showing the procedural equivalent of what I'm trying to do
in each statement.
Also, does anybody have a workaround for the bug in erase_key?
Thanks,
Scott
#include
));

on Fri Mar 23 2007, Scott Meyers
David Abrahams wrote:
Nothing; this is clearly a bug in MPL
As a workaround, I thought I'd write an erase_first function as shown below, but this seems to have the same problem. Perhaps this is because I'm using erase in my implementation, and erase_key may, I suppose, be implemented on top of erase.
It is *extremely* likely that erase_key and erase produce the same result.
More likely, I'm doing something wrong.
Not all that likely.
More likely still, the way I'm doing it is gross.
Well yeah. The un-gross way is to wait for Aleksey to fix it. He's unfortunately in a work crunch at the moment, but I'd guess he could address it within a couple of days.
I'd appreciate feedback on the implementation of my erase_first function, where I've put comments showing the procedural equivalent of what I'm trying to do in each statement.
Also, does anybody have a workaround for the bug in erase_key?
It's highly unlikely that any opportunity for such a workaround exists in the set code.
Thanks,
Scott
#include
#include #include #include #include #include namespace mpl = boost::mpl; using mpl::_1; using mpl::_2;
struct A {}; struct B {};
typedef mpl::set set1; typedef mpl::set set2;
// return Seq with the first occurrance of T removed template
struct erase_first { // i = Seq.find(T) typedef typename mpl::find ::type i; // found = (i == Seq.end()) ? false : true typedef typename mpl::if_< typename boost::is_same::type, mpl::false_, mpl::true_ >::type found;
mpl::if_< pred, mpl::false_, mpl::true_>::type is usually better written mpl::not_<pred>
// type = found ? Seq : Seq.erase(i) typedef typename mpl::if_
::type >::type type; };
From scratch (untested):
template

on Fri Mar 23 2007, David Abrahams
From scratch (untested):
And now, just by inspection...
template
struct erase_first { typedef typename mpl::find ::type i; typedef typename eval_if< boost::is_same
^::type
, mpl::identity<Seq> , mpl::erase
>::type type; }; HTH,
HTH-ly y'rs, -- Dave Abrahams Boost Consulting www.boost-consulting.com

On 3/23/07, Scott Meyers
// return Seq with the first occurrance of T removed template
struct erase_first { // i = Seq.find(T) typedef typename mpl::find ::type i; // found = (i == Seq.end()) ? false : true typedef typename mpl::if_< typename boost::is_same::type, mpl::false_, mpl::true_ >::type found;
// type = found ? Seq : Seq.erase(i)
// type = found ? Seq.erase(i) : Seq
typedef typename mpl::if_
::type >::type type;
typedef typename if_
};
BOOST_MPL_ASSERT(( mpl::equal< erase_first
::type, erase_first ::type ));
Or did I misunderstand? Tony

On 3/23/07, Scott Meyers
Any other suggestions?
Thanks,
Scott
Do you know what the bug in mpl is?
we have, essentially:
: eval_if<
has_key_implaux::set_tag::apply

on Fri Mar 23 2007, "Gottlob Frege"
And, unfortunately, although staring for the usual requisite hour, s_mask, although small (or because it is small), makes no sense to me.
In particular, I thought it would have a 'type' typedef'd somewhere in it, but I don't see it.
It inherits the ::type from its base class. -- Dave Abrahams Boost Consulting www.boost-consulting.com

Hi Scott, First of all, thanks for reporting this!
I expect the following code to compile cleanly. It does not.
#include
#include #include namespace mpl = boost::mpl; using mpl::_1; using mpl::_2;
struct A {}; struct B {};
typedef mpl::set set1; typedef mpl::set set2;
BOOST_MPL_ASSERT(( mpl::equal< mpl::erase_key
::type, mpl::erase_key ::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?
As David has already pointed out, your code is perfectly fine; it's a bug in the library. I'll look into fixing this within the next couple of days. Thanks for the report, -- Aleksey Gurtovoy MetaCommunications Engineering

Aleksey Gurtovoy writes:
As David has already pointed out, your code is perfectly fine; it's a bug in the library. I'll look into fixing this within the next couple of days.
Okay, this is fixed now (in the Boost CVS's HEAD), and the 'set' tests have been reworked to be more thorough. Once again, thanks for the report! -- Aleksey Gurtovoy MetaCommunications Engineering
participants (4)
-
Aleksey Gurtovoy
-
David Abrahams
-
Gottlob Frege
-
Scott Meyers