Solved

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

Posted on 2015-01-25
8
160 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now