Title
bitset
Status
c++11
Section
[bitset.cons]
Submitter
Christopher Jefferson

Created on 2010-03-07.00:00:00 last changed 154 months ago

Messages

Date: 2010-11-23.13:22:14

Proposed resolution:

  1. In the synopsis of header <bitset> in [template.bitset]/1, replace the fourth bitset constructor:
    explicit bitset(const char *str);
    template <class charT>
      explicit bitset(
        const charT *str,
        typename basic_string<charT>::size_type n = basic_string<charT>::npos,
        charT zero = charT('0'), charT one = charT('1'));
    
  2. In [bitset.cons]/8:
    explicit bitset(const char *str);
    template <class charT>
    explicit
    bitset(const charT *str,
           typename basic_string<charT>::size_type n = basic_string<charT>::npos,
           charT zero = charT('0'), charT one = charT('1'));
    

    Effects: Constructs an object of class bitset<N> as if by bitset(string(str)).

    
    bitset(
      n == basic_string<charT>::npos
        ? basic_string<charT>(str)
        : basic_string<charT>(str, n),
      0, n, zero, one)
    
Date: 2010-11-23.13:22:14

[ Adopted at 2010-11 Batavia ]

Date: 2010-10-21.19:06:53

[ Post-Rapperswil ]

The proposed resolution has two problems:

  • it fails to provide support for non-terminated strings, which could be easily added and constitutes an important use-case. For example, the following code would invoke UB with the current P/R:

    char s[4] = { '0', '1', '0', '1' }; // notice: not null-terminated!
    bitset<4> b(s, 0, 4);
    
    because it requires the evaluation (under the as-if rule, to be fair, but it doesn't matter) of basic_string<char>(s)
  • it promotes a consistency between the two bitset constructors that take a const std::string& and a const char*, respectively, while practice established by std::basic_string would recommend a different set of parameters. In particular, the constructor of std::basic_string that takes a const char* does not have a pos parameter

Moved to Tentatively Ready with revised wording provided by Alberto Ganesh Babati after 5 positive votes on c++std-lib.

Date: 2010-10-21.18:28:33

[ The proposed resolution has been reviewed by Stephan T. Lavavej. ]

Date: 2010-03-07.00:00:00

As mentioned on the boost mailing list:

The following code, valid in C++03, is broken in C++0x due to ambiguity between the "unsigned long long" and "char*" constructors.

#include <bitset>
std::bitset<10> b(0);
History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-11-23 13:22:14adminsetmessages: + msg5403
2010-11-14 13:10:57adminsetstatus: voting -> wp
2010-11-08 14:14:39adminsetstatus: ready -> voting
2010-10-21 19:06:53adminsetmessages: + msg4771
2010-10-21 19:06:53adminsetstatus: new -> ready
2010-10-21 18:28:33adminsetmessages: + msg1603
2010-10-21 18:28:33adminsetmessages: + msg1602
2010-03-07 00:00:00admincreate