Boost logo

Boost :

Subject: Re: [boost] [dynamic_bitset] Comparison operators without assertions
From: Edward Diener (eldiener_at_[hidden])
Date: 2017-04-30 15:13:02

On 4/27/2017 1:02 PM, Pavel Kretov via Boost wrote:
> Hi all.
> Looking through boost::dynamic_bitset code, I found a interesting
> inconsistency between its operator== and operator<. Namely, the first
> works well with bitsets of different size, while the second triggers
> an assertion:
> boost::dynamic_bitset<> a(std::string("111")),
> b(std::string("1110"));
> a == b; // false
> a < b; // Assertion `a.size() == b.size()' failed.
> This means that we cannot reliably use dynamic bitset within ordered
> containers like std::set or std::map.
> Since the standard library has distinct concepts of equality and
> equivalence (see [1]), it's fine to have different comparison
> behaviors in dynamic_bitset. However, as far as I can judge,
> equivalence is a metaphysically broader concept than equality, we
> shouldn't restrict it to bitsets of the same size only.
> So, the questions:
> 1. May I remove that assertion?
> (It won't be a breaking change, after all).
> 2. How about doing the same thing to bitwise operators, too? Instead
> of throwing an assertion if sizes don't match, it may be worth to
> generalize the operators definitions. I can see several possible
> schemes, but not all of them are consistent enough.

Are you suggesting that the <,>,<=, and >= operators always return
'false' if the sizes do not match, rather than assert ?

> 3. Shouldn't BOOST_ASSERT be used instead of the one from assert.h?

Possibly. I think the intention was always to assert, whereas
BOOST_ASSERT lets the assertion be overridden. I do agree with you that
the current way dynamic_bitset works with the assertion should have been

> ――― Pavel K.
> [1]:

Boost list run by bdawes at, gregod at, cpdaniel at, john at