2015-07-02 62 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