【问题标题】:Using boost::associative property map with boost::BIMAP interface使用带有 boost::BIMAP 接口的 boost::associative 属性映射
【发布时间】:2014-02-09 02:47:03
【问题描述】:

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

我有一个如下的 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. 

我知道,通过属性映射支持双映射。有关文档,请参阅 here。只是想知道我将如何使用关联属性映射。如果我可以为我的关联属性映射定义左或右 bimap,那也很好。请建议。

【问题讨论】:

  • 请让您的代码下次成为SSCCE?我们不得不猜测。我花了更多时间找出要包含哪些标题。这是浪费时间,并且会降低您获得答案的机会。 (我马上就知道答案了,但是之前没用过Boost Property Map……)

标签: c++ boost map boost-bimap


【解决方案1】:

您需要告诉它要使用 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);
} 

【讨论】:

    猜你喜欢
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 2012-11-03
    • 1970-01-01
    相关资源
    最近更新 更多