Using boost::associative property map with boost::BIMAP interface

帅比萌擦擦* 提交于 2019-12-02 05:48:38

问题


I am not able to implement associative property map interface of boost for a boost bimap.

I have a bimap as follows and I try to define a boost::associative property map for it. I want to use Put and Get helper functions for my bimap.. the code is as follows:

 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);

I get a compile error as

  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. 

I am aware, bimaps are supported through property maps. see here for documentation. Just wondering how would i use associative property map for it.. if i can define left or right bimap for my associative property map, that would also be fine. please suggest.


回答1:


You need to tell it which side of the bimap to use:

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;

So, see it 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);
} 


来源:https://stackoverflow.com/questions/21654594/using-boostassociative-property-map-with-boostbimap-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!