Solved

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

Posted on 2015-01-25
8
177 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ syntax question 9 48
Path to  STL Map header file 1 58
trigs fail! I thought I knew how to do trignometry 3 66
max float value 3 41
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

773 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