|
Boost Users : |
Subject: [Boost-users] multiindex composite key help
From: Uthpal Urubail (uthpal.urubail_at_[hidden])
Date: 2013-06-24 00:57:02
Looking for someone's help me to make correct use of boost composite key.
Requirement:
Given config and type get all cid's
Below example I am passing config =1; and type = 1; I am expecting all cid's matching both of them. i.e 1 and 2 only
However if you see the out output it is: 1,2,3,1,8,3
//----------
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <iostream>
#include <vector>
struct record
{
unsigned int cid;
unsigned int config;
unsigned int type;
//! default const..
record():cid(0),config(0),type(0){}
//! parm. const..
record(unsigned int _cid, unsigned int _config, unsigned int _type):
cid(_cid),config(_config),type(_type){}
};
using boost::multi_index_container;
using namespace boost::multi_index;
typedef multi_index_container<
record,
indexed_by<
ordered_non_unique<
composite_key<
record,
member<record,unsigned int,&record::config>,
member<record,unsigned int,&record::type>
>
>
>
> recordBookDef;
recordBookDef recordbook;
int main()
{
record obj1(1,1,1);
record obj2(2,2,1);
record obj3(3,3,1);
recordbook.insert(obj1);
recordbook.insert(obj2);
recordbook.insert(obj3);
record obj11(2,1,1);
record obj12(1,2,1);
record obj13(8,2,1);
recordbook.insert(obj11);
recordbook.insert(obj12);
recordbook.insert(obj13);
unsigned int config =1;
unsigned int type = 1;
recordBookDef::iterator it=recordbook.find(boost::make_tuple(config,type));
while(it!=recordbook.end())
{
//if(it->config == 1)
std::cout<<it->config<<",";
++it;
}
std::cout<<std::endl;
return 0;
}
Regards,
UJ
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net