Boost logo

Boost Users :

From: Hubert Schmid (kf1gmtvro69bnet5_at_[hidden])
Date: 2006-09-29 05:55:31


Hi,

I guess there is a bug in boost/multi_index/sequenced_index.hpp. The
following program fails to compile, because there is no matching
operator== for class C. But this operator shouldn't be required for
splice.

    #include "boost/multi_index/sequenced_index.hpp"
    #include "boost/multi_index_container.hpp"

    struct C { };

    int main()
    {
        using namespace boost;
        using namespace boost::multi_index;
        typedef multi_index_container<C, indexed_by<sequenced<> > > Cs;
        Cs cs;
        cs.push_back(C());
        cs.splice(cs.end(), cs, cs.begin()); // XXX: compile error
    }

The following program compiles, but both assertions fail at runtime:

    #include "boost/multi_index/sequenced_index.hpp"
    #include "boost/multi_index_container.hpp"

    int main()
    {
        using namespace boost;
        using namespace boost::multi_index;
        typedef multi_index_container<int, indexed_by<sequenced<> > > ints;
        ints foo;
        foo.push_back(42);
        ints bar;
        bar.push_back(42);
        foo.splice(foo.end(), bar, bar.begin());
        assert(foo.size() == 2);
        assert(bar.size() == 0);
    }

I have made both tests with the boost library in Debian/unstable
(version 1.33.1-7). I have also compared the source file
sequenced_index.hpp with the CVS-MAIN version (1.12). I guess the
following patch should fix this bug:

--- sequenced_index.hpp.orig 2006-09-29 11:38:06.000000000 +0200
+++ sequenced_index.hpp 2006-09-29 11:39:43.000000000 +0200
@@ -355,7 +355,7 @@
     BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i);
     BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,x);
     BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
- if(x==*this){
+ if(&x==this){
       if(position!=i)relink(position.get_node(),i.get_node());
     }
     else{
@@ -388,7 +388,7 @@
     BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x);
     BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
     BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
- if(x==*this){
+ if(&x==this){
       BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
       if(position!=last)relink(
         position.get_node(),first.get_node(),last.get_node());

regards, Hubert


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