将boost :: associative属性映射与boost :: BIMAP接口一起使用

时间:2014-02-09 02:47:03

标签: c++ boost map boost-bimap

我无法为boost bimap实现boost的关联属性map接口。

我有一个bimap如下,我尝试为它定义一个boost :: associative属性映射。我想为我的bimap使用Put和Get辅助函数..代码如下:

 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 个答案:

答案 0 :(得分: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);
} 
相关问题