Получить ключ из значения, используя карту свойств boost :: ассоциативно, определенную для boost :: bimap

Извините, что задали другой вопрос Вот, Я должен был быть более ясным о своих намерениях использовать boost :: bimaps.

Мой ключ, пары значений здесь уникальны. поэтому я хочу заполнить BIMAP, используя ключ, значение. и получить ключ, используя значение.

Со ссылкой на мой код и его решение Вот упомянутый @sehe. Вот что я хочу сделать с кодом:

1. define a bimap  (my_bimap )
2. define associative property map for left view of bimap  ( right_asso_bimap )
3. define associative property map for right view of bimap  ( left_asso_bimap )
4. fill the bimap using **left** view associative property map.
i.e.  use boost::put( left_asso_bimap, key, value )
5. Now using **right** view associative property map, retrieve key for given value
i.e. use boost::get( right_asso_bimap, value )

Вот мой код:

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

using namespace boost;

int main() {
typedef int vertex_descriptor_t;
namespace bm = boost::bimaps;
typedef bm::bimap< vertex_descriptor_t, bm::list_of<size_t> > vd_idx_bimap_t;
typedef boost::associative_property_map<vd_idx_bimap_t::left_map>    Lasso_vd_idx_bimap_t;
typedef boost::associative_property_map<vd_idx_bimap_t::right_map>   Rasso_vd_idx_bimap_t;

// define bimap and assoc prop map for it
vd_idx_bimap_t        my_bimap;
Lasso_vd_idx_bimap_t  Lmy_asso_bimap(my_bimap.left );
Rasso_vd_idx_bimap_t  Rmy_asso_bimap(my_bimap.right);

typedef typename vd_idx_bimap_t::value_type value_type;
my_bimap.insert( value_type( 1, 100 ) );
my_bimap.insert( value_type( 2, 200 ) );

int z = 1;
std::cout << "value = " << get ( my_bimap.left, z ) << std::endl;    // prints correctly value = 100

// use left asso bimap for inserting to bimap
boost::put( Lmy_asso_bimap, 3, 300 );

// print bimap using left view
for(auto t = my_bimap.left.begin(); t != my_bimap.left.end(); ++t)
std::cout << t->first << " " << t->second <<  "\n";

int y = 2;
z = boost::get( Lmy_asso_bimap, y  );
std::cout << "value = " << z << std::endl;

// Use right asso bimap to get key based on supplied value
y = 100;
**z = boost::get( Rmy_asso_bimap, y );**    // -->> error here
std::cout << "value = " << z << std::endl;

// print map again. (right view)
for(auto t = my_bimap.right.begin(); t != my_bimap.right.end(); ++t)
std::cout << t->first << " " << t->second <<  "\n";

}

ошибка ниже:

In file included from main.cpp:2:0: /usr/local/include/boost/property_map/property_map.hpp: In instantiation of 'boost::associative_property_map<UniquePairAssociativeContainer>::value_type& boost::associative_property_map<UniquePairAssociativeContainer>::operator[](const key_type&) const [with UniquePairAssociativeContainer = boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<int>, mpl_::na, mpl_::na, mpl_::na> > boost::associative_property_map<UniquePairAssociativeContainer>::reference = const int&; boost::associative_property_map<UniquePairAssociativeContainer>::value_type = const int; boost::associative_property_map<UniquePairAssociativeContainer>::key_type = int]':

/usr/local/include/boost/property_map/property_map.hpp:357:54:   required from 'Reference boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::associative_property_map<boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<int>, mpl_::na, mpl_::na, mpl_::na> > > Reference = const int&; K = int]'

main.cpp:42:39:   required from here /usr/local/include/boost/property_map/property_map.hpp:502:20: error: no match for 'operator[]' (operand types are 'boost::associative_property_map<boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<int>, mpl_::na, mpl_::na, mpl_::na> > >::C {aka boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<int>, mpl_::na, mpl_::na, mpl_::na> >}' and 'const key_type {aka const int}')
return (*m_c)[k];
^

Есть ли способ, который я мог бы использовать, Положить, используя левую ассоциативную карту свойств, и Получить для правых ассоциативных карт свойств? Функции Put и Get предназначены для универсальности. Я мог бы использовать вставки и т. Д., Но я хочу избежать этого. @ Sehe, спасибо за эти ответы ранее. Я должен был сам рассказать об этой проблеме раньше

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector