I have a multi_index_container with an index that is a composite_key.
But I can not find a way to erase an element by its key.
Please see below:
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/composite_key.hpp>
using namespace boost::multi_index;
struct Point
{
int x, y;
};
void func()
{
multi_index_container<Point,indexed_by<
hashed_unique<
composite_key<Point,
member<Point,int,&Point::x>,
member<Point,int,&Point::y> >
> > > points;
points.find( boost::make_tuple( 3, 3 ) ); // <- works
points.erase( boost::make_tuple( 3, 3 ) ); // <- failes to compile
}
erase(key) works for indices that are not composite. But I am unable to find the correct syntax for composite keys.
erasedoesn’t have the type of overloads that allow for interoperation with tuples (technically, this relates to the concept of compatible extensions.) But you can have the same effect with a little more code: