2014-02-09 64 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