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
Solved

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

Posted on 2015-01-25
8
186 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

829 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