Link to home
Start Free TrialLog in
Avatar of jxbma
jxbmaFlag for United States of America

asked on

How do I retrieve a value from a boost::bimap by key in VS C++?

Hi:

First time using boost::bimap.

I have constructed the following typedef:
typedef boost::bimap<std::basic_string<TCHAR>, int> argvType;

I load values into the bimap:
argvType arguments;

for (int index = 0; index < argc; index++)
{
      arguments.insert(argvType::value_type(argv[index], index));
}

How do I retrieve a value from the bimap assuming I'm using the following key:
std::basic_string<TCHAR> fileIn = L"foo";

I want to retrieve the string value in the map associated with the key.
I know there's probably better ways to do this, but I'd like to stick with
the implementation I've started.

I would think I should be able to use a [] operator or a get().
How do this?

Thanks,
JohnB
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jxbma

ASKER

Mmm....
I think I'm missing something there.

I get the following compilation error:
Error	138	error C2440: 'initializing' : cannot convert from 'boost::bimaps::detail::map_view_iterator<Tag,BimapType>' 
o 'boost::bimaps::detail::set_view_iterator<boost::multi_index::detail::bidir_node_iterator
<boost::multi_index::detail::ordered_index_node<Super>>>'	
c:\affectiva\source\affdex-windows-sdk\affdexfacewindowssdkconsoleapp\affdex-console-app.cpp	97

Open in new window

Avatar of jxbma

ASKER

All I really want to do is to retrieve the "value" at that key if it exists.
Not clear to me yet how to do that.
Ooops, sorry, should have been

argvType::right_map::iterator it = argument.right.find(fileIn);

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jxbma

ASKER

Mmmm...
Still missing something here.

std::basic_string<TCHAR> fileIn = L"-f";
argvType::right_map::iterator it = arguments.right.find(fileIn);

Open in new window


still produces:
Error      141      error C2664: 'int boost::bimaps::container_adaptor::detail::key_to_base_identity<int,KeyType>::operator ()(Key &) const' : cannot convert argument 1 from 'const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' to 'const int &'      c:\boost\include\boost\bimap\container_adaptor\associative_container_adaptor.hpp      194
Error      142      error C2780: 'boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<Super>> boost::multi_index::detail::ordered_index<boost::multi_index::member<boost::bimaps::relation::detail::relation_storage<TA,TB,true>,int,pointer-to-member(0x1c)>,std::less<int>,SuperMeta,boost::mpl::vector1<T0>,boost::multi_index::detail::ordered_unique_tag>::find(const CompatibleKey &,const CompatibleCompare &) const' : expects 2 arguments - 1 provided      c:\boost\include\boost\bimap\container_adaptor\associative_container_adaptor.hpp      195