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.

### 186. bitset::set() second parameter should be bool

Section: 22.9.2.3 [bitset.members] Status: CD1 Submitter: Darin Adler Opened: 1999-08-13 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [bitset.members].

View all issues with CD1 status.

Discussion:

In section 22.9.2.3 [bitset.members], paragraph 13 defines the bitset::set operation to take a second parameter of type int. The function tests whether this value is non-zero to determine whether to set the bit to true or false. The type of this second parameter should be bool. For one thing, the intent is to specify a Boolean value. For another, the result type from test() is bool. In addition, it's possible to slice an integer that's larger than an int. This can't happen with bool, since conversion to bool has the semantic of translating 0 to false and any non-zero value to true.

Proposed resolution:

In 22.9.2 [template.bitset] Para 1 Replace:

>     bitset<N>& set(size_t pos, int val = true );

With:

>     bitset<N>& set(size_t pos, bool val = true );

In 22.9.2.3 [bitset.members] Para 12(.5) Replace:

>     bitset<N>& set(size_t pos, int val = 1 );

With:

>     bitset<N>& set(size_t pos, bool val = true );

[Kona: The LWG agrees with the description. Andy Sawyer will work on better P/R wording.]

[Post-Tokyo: Andy provided the above wording.]

Rationale:

`bool` is a better choice. It is believed that binary compatibility is not an issue, because this member function is usually implemented as `inline`, and because it is already the case that users cannot rely on the type of a pointer to a nonvirtual member of a standard library class.