|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-04-14 08:12:35
Gennaro Prota <gennaro_prota_at_[hidden]> writes:
> On Wed, 14 Apr 2004 09:34:14 +0200, Gennaro Prota
> <gennaro_prota_at_[hidden]> wrote:
>
>>I also added
>>the following functions: find_first, find_next, get_allocator(),
>>max_size(), intersects() and empty().
>
> The function intersects() was a user request. It returns true if and
> only if the two bitsets have any bit "in common", i.e.:
>
> a.intersects(b) == true <=> An index i < a.size(), b.size() exists
> such as a[i] == true and b[i] == true
>
> Logically, this is the same as doing (a & b).any() [except that
> currently a & b requires the two bitsets to have the same size - this
> restriction will likely be removed in the future if we reach a
> consensus on semantics] but is faster because it doesn't require any
> copy and can be done with one pass through the blocks
>
> I was thinking, however: what about returning the index of the first
> bit in common (or npos), instead of true/false?
Ugh, not bit indices, at least not with *that* name!
if (intersects(a,b)) // oops
{
}
Maybe optional<std::size_t>?
> Secondly, does anyone find confusing that empty() means size() == 0
> rather than "the set is empty"?
Not at all. This is not a std::set<> after all. It's well known that
it has the semantics of an array. But maybe you should rename it
bit_array or bit_vector instead of dynamic_bitset ;-)
> Someone could be tempted to write e.g.
>
> if ((a ^ b).empty()) ...
>
> instead of
>
> if ((a ^ b).none()) ...
IMO
if (a ^ b)
should be supported. But then again, this is making me think of
expression templates ;-)
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk