This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

693. std::bitset::all() missing

Section: 22.9.2 [template.bitset] Status: CD1 Submitter: Martin Sebor Opened: 2007-06-22 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [template.bitset].

View all issues with CD1 status.

Discussion:

The bitset class template provides the member function any() to determine whether an object of the type has any bits set, and the member function none() to determine whether all of an object's bits are clear. However, the template does not provide a corresponding function to discover whether a bitset object has all its bits set. While it is possible, even easy, to obtain this information by comparing the result of count() with the result of size() for equality (i.e., via b.count() == b.size()) the operation is less efficient than a member function designed specifically for that purpose could be. (count() must count all non-zero bits in a bitset a word at a time while all() could stop counting as soon as it encountered the first word with a zero bit).

Proposed resolution:

Add a declaration of the new member function all() to the defintion of the bitset template in 22.9.2 [template.bitset], p1, right above the declaration of any() as shown below:

bool operator!=(const bitset<N>& rhs) const;
bool test(size_t pos) const;
bool all() const;
bool any() const;
bool none() const;

Add a description of the new member function to the end of 22.9.2.3 [bitset.members] with the following text:

bool all() const;

Returns: count() == size().

In addition, change the description of any() and none() for consistency with all() as follows:

bool any() const;

Returns: true if any bit in *this is onecount() != 0.

bool none() const;

Returns: true if no bit in *this is onecount() == 0.