I have created a boost::multi_index
successfully and inserted values too. I have two hashed indices to the multi_index. Both are member functions, but one is unique and the other one is non-unique.
I am trying to figure out the way to get the values from the container using the values of the hashes. I could not understand how I should do that. I searched online, and I see there are a lot of people have asked this question. But I dont understand what needs to be done. I saw a few solutions in C++11 but I dont use C++11 and I dont understand whats being done. Can someone please explain to me how to use it? Given below is my code,
#include "stdafx.h"
#include<multi_index_container.hpp>
#include<boost/multi_index/hashed_index.hpp>
#include<boost/multi_index/mem_fun.hpp>
#include<boost/multi_index/tag.hpp>
class RetClass
{
int a, b;
};
class StoreMe
{
RetClass ex;
std::string exStr;
int id;
public:
void setId(RetClass a)
{
ex = a;
};
virtual const RetClass& getId() const { return ex; }
virtual std::string getIdString() const { return exStr; }
int getUniqueId() const { return id; }
};
struct IndexByStringId{};
struct IndexByUniqueId{};
typedef boost::multi_index_container<
StoreMe,
boost::multi_index::indexed_by<
boost::multi_index::hashed_unique<
boost::multi_index::tag<IndexByStringId>,
boost::multi_index::const_mem_fun<StoreMe, std::string, &StoreMe::getIdString>
>,
boost::multi_index::hashed_non_unique<
boost::multi_index::tag<IndexByUniqueId>,
boost::multi_index::const_mem_fun<StoreMe, int, &StoreMe::getUniqueId>
>
>
> mi_storeMe;
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
I want to be able to,
- Get the values non-unique Id maps to
- Get the value (if it exists) that the unique Id maps to
Please let me know the correct/simplest way to get this done. Also I don't use C++11.