Solved

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

Posted on 2015-01-25
8
209 Views
Last Modified: 2015-03-06
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
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 40569546
You need to use one 'view' of your bimap to do the lookup, i.e.

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

Open in new window


Also check out this decent tutorial about using bimaps: http://mybyteofcode.blogspot.de/2010/02/representing-bidirectional-relationship.html ("Representing bidirectional relationship with boost::bimap")
0
 
LVL 1

Author Comment

by:jxbma
ID: 40569647
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

0
 
LVL 1

Author Comment

by:jxbma
ID: 40569653
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 40569689
Ooops, sorry, should have been

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

Open in new window

0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 250 total points
ID: 40569701
A good lecture on bimap starting at at 34:50
https://www.youtube.com/watch?v=FM-fUjhoCp0
0
 
LVL 1

Author Comment

by:jxbma
ID: 40569704
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question