2014-02-09 60 views
2

我無法爲boost bimap實現boost的關聯屬性映射接口。使用具有boost :: BIMAP接口的boost :: associative property map

我有一個bimap如下,我嘗試爲它定義一個boost :: associative屬性映射。我想使用PUT和GET輔助功能爲我的bimap ..代碼如下:

typedef boost::bimaps::bimap< vertex_descriptor_t, size_t >  vd_idx_bimap_t; 
typedef boost::associative_property_map<vd_idx_bimap_t>   asso_vd_idx_bimap_t; 

// define bimap 
vd_idx_bimap_t  my_bimap; 
asso_vd_idx_bimap_t my_asso_bimap(my_bimap); 

我得到一個編譯錯誤作爲

error: no type named âsecond_typeâ in âboost::bimaps::container_adaptor::container_adaptor<boost::multi_index::detail::ordered_index<boost::m.... goes on long list. 

我所知,bimaps通過屬性映射支持。有關文檔,請參閱here。只是想知道我將如何使用聯想屬性映射。如果我可以爲我的聯想屬性映射定義左側或右側bimap,那也可以。請建議。

+1

請一個SSCCE下一次你的代碼?我們不得不猜測。我花了更多時間找出要包含哪些標題。這是浪費時間,降低獲得答案的機會。 (我馬上就知道答案,但之前沒有使用過Boost Property Map ...) – sehe

回答

2

你需要告訴它介紹bimap的使用哪一方:

typedef boost::associative_property_map<vd_idx_bimap_t::left_map> asso_vd_idx_bimap_t; 
// OR 
typedef boost::associative_property_map<vd_idx_bimap_t::right_map> asso_vd_idx_bimap_t; 

所以,看到它Live on Coliru

#include <boost/bimap.hpp> 
#include <boost/property_map/property_map.hpp> 
#include <iostream> 

using namespace boost; 

int main() 
{ 
    typedef int vertex_descriptor_t; 
    typedef boost::bimaps::bimap< vertex_descriptor_t, size_t > vd_idx_bimap_t; 
    typedef boost::associative_property_map<vd_idx_bimap_t::left_map> asso_vd_idx_bimap_t; 

    // define bimap 
    vd_idx_bimap_t  my_bimap; 
    asso_vd_idx_bimap_t my_asso_bimap(my_bimap.left); 
} 
+0

非常感謝我現在正在工作。 – Pogo