Title
bitset::set() second parameter should be bool
Status
cd1
Section
[bitset.members]
Submitter
Darin Adler

Created on 1999-08-13.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

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.

Date: 2010-10-21.18:28:33

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

Date: 2010-10-21.18:28:33

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

Date: 2010-10-21.18:28:33

Proposed resolution:

In [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 [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 );
Date: 1999-08-13.00:00:00

In section [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.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1797
2010-10-21 18:28:33adminsetmessages: + msg1796
2010-10-21 18:28:33adminsetmessages: + msg1795
2010-10-21 18:28:33adminsetmessages: + msg1794
1999-08-13 00:00:00admincreate