Boost logo

Boost Users :

Subject: [Boost-users] [Dynamic Bitset] Comparableness between different sized sets
From: Etienne Philip Pretorius (icewolfhunter_at_[hidden])
Date: 2010-05-01 09:20:33


Hello List,

Just a quick question, why can you not compare between different sized
dynamic bitsets?

As I am trying to add some operators to it in my application so that it
can become a large interger type.... (ie in excess of 256 bits)

    boost::dynamic_bitset<>
    operator++(
        boost::dynamic_bitset<>& x,
        int
    ) {
        bool c = true;
        for(boost::dynamic_bitset<>::size_type i = 0; c && (i <
x.size()); i++) {
            if(x[i]) {
                c = true;
            }else{
                c = false;
            }
            x[i].flip();
        }
        if(c) {
            x.resize(x.size()+1,true);
        }
        return x;
    };

If I have a for loop and the post incremental operation increases the
size of the bitset then operator < bails with an assertion failure :

/usr/include/boost/dynamic_bitset/dynamic_bitset.hpp:1288: bool
boost::operator<(const boost::dynamic_bitset<Block, Allocator>&, const
boost::dynamic_bitset<Block, Allocator>&) [with Block = long unsigned
int, Allocator = std::allocator<long unsigned int>]: Assertion `a.size()
== b.size()' failed.
Aborted

Etienne

-- 
This message has been scanned for viruses and
dangerous content by Pinpoint, and is
believed to be clean.

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