Multi_index Container

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Multi_index Container

Soni, Aashit
Multi_index Container

Hi all,

I am newbie to Boost library. I am trying to use multi_index_container library in my project. The problem I have at my hands needs One Hash index and one ordered indexed. I refer the Boost tutorial and Advance topic and tried to write the following snippet. But when I compiled it gives compilation error. I searched lot of different options and tried to fix it but I could not able to do it so.

If you can guide me how to shut the compilation errors it will be great. If anyone of you is having any decent example tried out for Hash having ordered indexes please send it to me so I can go through and build my logic on top of that….


Code Follows.

I am using MSVC SP6 on Win XP .
/*****************************************/

#define BOOST_MULTI_INDEX_CHECK_INVARIANT
#include <boost/config.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>


using boost::multi_index_container;
using namespace boost::multi_index;

struct employee
{
  int         id;
  std::string name;
  int         ssnumber;

  employee(int id,const std::string& name,int ssnumber):
    id(id),name(name),ssnumber(ssnumber){}

  bool operator<(const employee& e)const{return id<e.id;}
};

struct id{};
struct name{};
struct ssnumber{};


typedef multi_index_container<
  employee,
  indexed_by<
    // sort by employee::operator<
    ordered_unique<tag<id>,BOOST_MULTI_INDEX_MEMBER(employee,int,id) >,
   
    // sort by less<string> on name
    ordered_non_unique<tag<name>,BOOST_MULTI_INDEX_MEMBER(employee,std::string,name) >,
   
    // hashed on ssnumber
    hashed_unique<tag<ssnumber>,BOOST_MULTI_INDEX_MEMBER(employee,int,ssnumber) >
  >
> employee_set;


void main()
{

        employee_set es;

        typedef employee_set::index<employee_set,ssnumber>::type employee_set_by_ssn;

       

        es.insert(employee(1,"aashit",323));
        es.insert(employee(3,"chetan",443));

        employee_set_by_ssn& ssn_index=es.get<2>();



}






--------------------Configuration: MyHash - Win32 Debug--------------------
Compiling...
main.cpp
f:\practice\multiindex_examples\myhash\main.cpp(53) : error C2039: 'index<class boost::multi_index::multi_index_container<struct employee,struct boost::multi_index::indexed_by<struct boost::multi_index::ordered_unique<struct boost::multi_index::tag<

struct id,struct boost::mpl::na,struct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,int,0>,struct boost::mpl::na>,struct boost::multi_index::ordered_non_unique<struct boost::multi_index::tag<struct name,struct boost::mpl:

:na,struct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,4>,struct boost::mpl::na>,struct boost::multi_index::hashed_unique<struct boo

st::multi_index::tag<struct ssnumber,struct boost::mpl::na,struct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,int,20>,struct boost::mpl::na,struct boost::mpl::na>,struct boost::mpl::na,struct boost::mpl::na>,class std::a

llocator<struct employee> >,struct ssnumber>' : is not a member of 'multi_index_container<struct employee,struct boost::multi_index::indexed_by<struct boost::multi_index::ordered_unique<struct boost::multi_index::tag<struct id,struct boost::mpl::na,

struct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,int,0>,struct boost::mpl::na>,struct boost::multi_index::ordered_non_unique<struct boost::multi_index::tag<struct name,struct boost::mpl::na,struct boost::mpl::na>,struc

t boost::multi_index::member_offset<struct employee,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,4>,struct boost::mpl::na>,struct boost::multi_index::hashed_unique<struct boost::multi_index::tag<struct ssnu

mber,struct boost::mpl::na,struct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,int,20>,struct boost::mpl::na,struct boost::mpl::na>,struct boost::mpl::na,struct boost::mpl::na>,class std::allocator<struct employee> >'

f:\practice\multiindex_examples\myhash\main.cpp(53) : error C2146: syntax error : missing ';' before identifier 'employee_set_by_ssn'

f:\practice\multiindex_examples\myhash\main.cpp(53) : error C2065: 'employee_set_by_ssn' : undeclared identifier
f:\practice\multiindex_examples\myhash\main.cpp(60) : error C2065: 'ssn_index' : undeclared identifier
f:\practice\multiindex_examples\myhash\main.cpp(60) : error C2039: 'get' : is not a member of 'multi_index_container<struct employee,struct boost::multi_index::indexed_by<struct boost::multi_index::ordered_unique<struct boost::multi_index::tag<struc

t id,struct boost::mpl::na,struct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,int,0>,struct boost::mpl::na>,struct boost::multi_index::ordered_non_unique<struct boost::multi_index::tag<struct name,struct boost::mpl::na,s

truct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,4>,struct boost::mpl::na>,struct boost::multi_index::hashed_unique<struct boost::m

ulti_index::tag<struct ssnumber,struct boost::mpl::na,struct boost::mpl::na>,struct boost::multi_index::member_offset<struct employee,int,20>,struct boost::mpl::na,struct boost::mpl::na>,struct boost::mpl::na,struct boost::mpl::na>,class std::alloca

tor<struct employee> >'
f:\practice\multiindex_examples\myhash\main.cpp(60) : error C2059: syntax error : ')'
Error executing cl.exe.

main.obj - 6 error(s), 0 warning(s)

  A a s h i t 



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi_index Container

Joaquin M LópezMuñoz
Hello Aashit,

"Soni, Aashit" ha escrito:

Hi all,

I am newbie to Boost library. I am trying to use multi_index_container library in my project. The problem I have at my hands needs One Hash index and one ordered indexed. I refer the Boost tutorial and Advance topic and tried to write the following snippet. But when I compiled it gives compilation error. I searched lot of different options and tried to fix it but I could not able to do it so.

If you can guide me how to shut the compilation errors it will be great. If anyone of you is having any decent example tried out for Hash having ordered indexes please send it to me so I can go through and build my logic on top of that….

Code Follows.

I am using MSVC SP6 on Win XP .

This is primarily the problem: To make MSVC 6.0 compile a program
using Boost.MultiIndex you've got to observe some stricter rules than
in the normal case. Please read the section on MSVC 6.0 at

http://boost.org/libs/multi_index/doc/compiler_specifics.html#msvc_60
 

        typedef employee_set::index<employee_set,ssnumber>::type employee_set_by_ssn;
Problem #1: MSVC 6.0 does not support the "index" nested typedef. Instead, write

        typedef index<employee_set,ssnumber>::type employee_set_by_ssn;

        employee_set_by_ssn& ssn_index=es.get<2>();
Problem #2: MSVC 6.0 does not support the get member function, use the global
version instead:

        employee_set_by_ssn& ssn_index=get<2>(es);

With these changes, and also tweaking /Zm and /ZI (as explained in the
aforementioned section), your program compiles. Bare in mind that your
compiler is very old and broken and making Boost.MultiIndex work for it
can be quite a challenge, although it is doable. Good luck with your project,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Reply | Threaded
Open this post in threaded view
|

Re: Multi_index Container

EMalenfant
In reply to this post by Soni, Aashit
From: Soni, Aashit [mailto:[hidden email]]
>
>         typedef
> employee_set::index<employee_set,ssnumber>::type employee_set_by_ssn;
>

I'm not a seasoned user of the MultiIndex library but, looking at the
documentation, it seems that the above should be written as:

        typedef employee_set::index<ssnumber>::type employee_set_by_ssn;

HTH,
-----------------------------
Éric
A conclusion is the place where you got tired of thinking


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi_index Container

Soni, Aashit
In reply to this post by Soni, Aashit
Hi Joaquín, Éric
 
I appreciate your response, Before that I got some workaround from the web and the snippet I have written to port it to my existing project worked until I face real problem.
 
My observation is like when I have Ordered_index with std::string, the code I have written compiles really well and works also. But when I remove this ordered_index, the code does not compile.
 
Here is the code that compiles: <<Multi_index_container_working.txt>>
 
Here is the code that does not compile: <<Multi_index_container_not_working.txt>>
 
 
If you see the difference I have only two lines commented.
 
...  //ordered_non_unique<tag<name>,BOOST_MULTI_INDEX_MEMBER(employee,std::string,name) >, ....
 
....  //typedef boost::multi_index::index<employee_set,name>::type employee_set_by_name;...
 
Same boost::multi_index::index<employee_set,ssnumber>::type is not working if the std::string is not indexed.
 
 
right now I am working with dummy string. But I need to scrap the string and have some real code in place that should go into my project. If I am not able to solve this. I can not use multi_index_container and it is real loss for me.
 
 
Help always appreciated. Thanks in advance.
 
aashit
 
ps: please consider these txt files are cpp files.
 
 
 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Joaquín Mª López Muñoz
Sent: Tuesday, February 07, 2006 9:39 PM
To: [hidden email]
Subject: Re: [Boost-users] Multi_index Container

Hello Aashit,

"Soni, Aashit" ha escrito:

Hi all,

I am newbie to Boost library. I am trying to use multi_index_container library in my project. The problem I have at my hands needs One Hash index and one ordered indexed. I refer the Boost tutorial and Advance topic and tried to write the following snippet. But when I compiled it gives compilation error. I searched lot of different options and tried to fix it but I could not able to do it so.

If you can guide me how to shut the compilation errors it will be great. If anyone of you is having any decent example tried out for Hash having ordered indexes please send it to me so I can go through and build my logic on top of that….

Code Follows.

I am using MSVC SP6 on Win XP .

This is primarily the problem: To make MSVC 6.0 compile a program
using Boost.MultiIndex you've got to observe some stricter rules than
in the normal case. Please read the section on MSVC 6.0 at

http://boost.org/libs/multi_index/doc/compiler_specifics.html#msvc_60
 

        typedef employee_set::index<employee_set,ssnumber>::type employee_set_by_ssn;
Problem #1: MSVC 6.0 does not support the "index" nested typedef. Instead, write

        typedef index<employee_set,ssnumber>::type employee_set_by_ssn;

        employee_set_by_ssn& ssn_index=es.get<2>();
Problem #2: MSVC 6.0 does not support the get member function, use the global
version instead:

        employee_set_by_ssn& ssn_index=get<2>(es);

With these changes, and also tweaking /Zm and /ZI (as explained in the
aforementioned section), your program compiles. Bare in mind that your
compiler is very old and broken and making Boost.MultiIndex work for it
can be quite a challenge, although it is doable. Good luck with your project,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Multi_index_container_working.txt (2K) Download Attachment
Multi_index_container_not_working.txt (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Multi_index Container

Joaquin M LópezMuñoz
"Soni, Aashit" ha escrito:
 
Hi Joaquín, Éric
I appreciate your response, Before that I got some workaround from the web and the snippet I have written to port it to my existing project worked until I face real problemMy observation is like when I have Ordered_index with std::string, the code I have written compiles really well and works also. But when I remove this ordered_index, the code does not compile.Here is the code that compiles: <<Multi_index_container_working.txt>>Here is the code that does not compile: <<Multi_index_container_not_working.txt>>If you see the difference I have only two lines commented.


Yes, I'm able to reproduce the problem you report under MSVC 6.0.
Two remarks:

* The problem does not show with the CVS version of Boost.MultiIndex (to
be shipped in Boost 1.34), as it includes a number of optimizations alleviating
the choking of MSVC 6.0 with very long symbol names, which is the core
reason for this weird behavior.
* Until you switch to Boost 1.34 (and even when you do), you can try avoiding
the use of tags and using numeric identifiers instead. Tags add some stress to
such a weak compiler as MSVC 6.0. The attached file is a variation of your
Multi_index_container_not_working.txt file where tags have been suppressed
and numerical identifiers used instead. I have checked it out to compile
and work OK under MSVC 6.0.

I hope this helps, please keep me informed otherwise,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
 
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


aashit.cpp (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Multi_index Container

Soni, Aashit
In reply to this post by Soni, Aashit
Hi Joaquín
 
 
It worked fine. Thanks for the quick answer. I really appreciate this.
 
 
now, I can go ahead and use it in my project.
 
regards,
aashit


From: [hidden email] [mailto:[hidden email]] On Behalf Of Joaquín Mª López Muñoz
Sent: Wednesday, February 08, 2006 1:16 PM
To: [hidden email]
Subject: Re: [Boost-users] Multi_index Container

"Soni, Aashit" ha escrito:
 
Hi Joaquín, Éric
I appreciate your response, Before that I got some workaround from the web and the snippet I have written to port it to my existing project worked until I face real problemMy observation is like when I have Ordered_index with std::string, the code I have written compiles really well and works also. But when I remove this ordered_index, the code does not compile.Here is the code that compiles: <<Multi_index_container_working.txt>>Here is the code that does not compile: <<Multi_index_container_not_working.txt>>If you see the difference I have only two lines commented.


Yes, I'm able to reproduce the problem you report under MSVC 6.0.
Two remarks:

* The problem does not show with the CVS version of Boost.MultiIndex (to
be shipped in Boost 1.34), as it includes a number of optimizations alleviating
the choking of MSVC 6.0 with very long symbol names, which is the core
reason for this weird behavior.
* Until you switch to Boost 1.34 (and even when you do), you can try avoiding
the use of tags and using numeric identifiers instead. Tags add some stress to
such a weak compiler as MSVC 6.0. The attached file is a variation of your
Multi_index_container_not_working.txt file where tags have been suppressed
and numerical identifiers used instead. I have checked it out to compile
and work OK under MSVC 6.0.

I hope this helps, please keep me informed otherwise,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
 


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users