[Boost-users] Multi Index with BOOST_AUTO question.

60 views
Skip to first unread message

Surya Kiran Gullapalli

unread,
Oct 13, 2009, 1:13:27 PM10/13/09
to boost...@lists.boost.org
Hello all,
I'm a newbie to multi-index. I ran into a strange problem with VS2008. When using BOOST_AUTO with multi-index I'm getting compilation errors (C2248) . Please see the following code.

<snip>

#include <iostream>
#include <string>
using namespace std ;

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>

#include <boost/foreach.hpp>
#include <boost/typeof/typeof.hpp>
using namespace boost ;
using namespace boost::multi_index ;


class Test
{
friend bool operator< (const Test& p_lhs, const Test& p_rhs)
{ return p_lhs._i < p_rhs._i ; }

friend ostream& operator << (ostream& os, const Test& p_test)
{
os << "Integer: " << p_test._i << "\tString: " << p_test._s ; 
return os ;
}

private:
int _i ;
string _s ;

public:
Test (int i, string s): _i(i), _s(s) { }

string getString (void) const { return _s ; }
} ;

struct byNumber { } ;
struct byString { } ;

int main (void)
{
typedef
multi_index_container <Test, indexed_by <
ordered_unique<tag<byNumber>, identity <Test> >
, ordered_non_unique < tag<byString>, BOOST_MULTI_INDEX_CONST_MEM_FUN(Test, string, getString) >
> > Container ;

typedef Container::index<byNumber>::type TestByNumber ;
typedef Container::index<byString>::type TestByString ;

Container c ;

c.insert (Test(5, "Surya")) ;
c.insert (Test(15, "Kiran")) ;

//TestByNumber& tests = c.get<byNumber>() ;
BOOST_AUTO(tests, c.get<byNumber>()) ;

BOOST_FOREACH (Test t, tests)
cout << t << endl ;

return 0 ;
}

</snip>

Compilation for this case fails with C2248. If I replace the BOOST_AUTO with the previous line's statement, compilation goes well. This happens with VS2008 only. with VS2005, there's no issue with BOOST_AUTO.

Am I missing something here?

Thanks,
Surya

Igor R

unread,
Oct 13, 2009, 1:18:14 PM10/13/09
to boost...@lists.boost.org
BOOST_AUTO(tests, c.get<byNumber>()) ;
 
try:
BOOST_AUTO(&tests, c.get<byNumber>()) ;

Surya Kiran Gullapalli

unread,
Oct 13, 2009, 1:24:21 PM10/13/09
to boost...@lists.boost.org
Thanks,
It worked. What is the difference ?. Which is correct ?

Surya 

Igor R

unread,
Oct 13, 2009, 1:29:48 PM10/13/09
to boost...@lists.boost.org
It worked. What is the difference ?. Which is correct ?
 
BOOST_AUTO(a, A) ; // is A a;
BOOST_AUTO(&a, A) ; // is A &a;
 
Since you can't copy the index, you should define a reference.

Surya Kiran Gullapalli

unread,
Oct 13, 2009, 1:33:30 PM10/13/09
to boost...@lists.boost.org
I got that. I've looked at Boost.Typeof documentation. But why was it working with VS2005 ?

Thanks,
Surya

Igor R

unread,
Oct 13, 2009, 1:39:55 PM10/13/09
to boost...@lists.boost.org
I got that. I've looked at Boost.Typeof documentation. But why was it working with VS2005 ?
 
 
Because in VS2005 index copying was not blocked (due to some compiler limitations) - it just would cause a crash in any subsequent operation with that copy :).

Igor R

unread,
Oct 13, 2009, 1:41:47 PM10/13/09
to boost...@lists.boost.org
Reply all
Reply to author
Forward
0 new messages