|
Boost : |
Subject: [boost] [dynamic_bitset] Comparison operators without assertions
From: Pavel Kretov (firegurafiku_at_[hidden])
Date: 2017-04-27 17:02:53
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.
3. Shouldn't BOOST_ASSERT be used instead of the one from assert.h?
――― Pavel K.
[1]: http://en.cppreference.com/w/cpp/concept/EqualityComparable
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk