2015-07-02 64 views
0

我有一个boost unordered_map容器(mymap),并且我想删除一些预测器对它们返回true的键。从boost中删除特定的键unordered_map

boost::range::remove_if(mymap, ((boost::bind(&mesh::type, (boost::bind(&map_type::value_type::first, _1)))) == EDGE)); 

啮合::类型被定义为以下:

class mesh 
{ 
    ... 
    Type type() const; 
    ... 
} 

和 “边缘” 是 “类型枚举” 中的一个。

这里是我得到的错误:

error: non-static const member ‘const mesh std::pair<const mesh, std::vector<std::vector<Point> > >::first’, can’t use default assignment operator 

我使用boost版本1.53和C++ 03。

+2

请始终发布[最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。 –

+0

如果您需要通过除地图键之外的其他东西进行查找,通常这是您需要具有(a)多个索引或(b)异构查找 – sehe

回答

2
// define this, either as a static member function or in a 
// private namespace... 
bool is_edge(const map_type::value_type& vt) 
{ 
    // note: concerned with the key, not the data 
    return vt.first.type() == EDGE; 
} 

// ... and avoid all the unreadable bind nastiness completely 
boost::range::remove_if(mymap, is_edge); 
+0

+1的标志。这看起来可能是OP想要实现的 – sehe