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