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.
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.
Objects of the
bitset class template specializations can
be constructed from and explicitly converted to values of the widest
C++ integer type,
unsigned long. With the introduction
long long into the language the template should be
enhanced to make it possible to interoperate with values of this type
as well, or perhaps
uintmax_t. See c++std-lib-18274 for
a brief discussion in support of this change.
For simplicity, instead of adding overloads for
long and dealing with possible ambiguities in the spec, replace
bitset ctor that takes an
argument with one taking
unsigned long long in the
definition of the template as shown below. (The standard permits
implementations to add overloads on other integer types or employ
template tricks to achieve the same effect provided they don't cause
ambiguities or changes in behavior.)
// [bitset.cons] constructors: bitset(); bitset(unsigned long val); template<class charT, class traits, class Allocator> explicit bitset( const basic_string<charT,traits,Allocator>& str, typename basic_string<charT,traits,Allocator>::size_type pos = 0, typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos);
Make a corresponding change in 184.108.40.206 [bitset.cons], p2:
bitset(unsigned long val);
Effects: Constructs an object of class bitset<N>, initializing the first
Mbit positions to the corresponding bit values in
Mis the smaller of
Nand the number of bits in the value representation (section [basic.types]) of
unsigned long. If
M < N, the remaining bit positions are initialized to zero.
Additionally, introduce a new member function
to make it possible to convert
bitset to values of the
new type. Add the following declaration to the definition of the
template, immediate after the declaration of
in 22.9.2 [template.bitset], p1, as shown below:
// element access: bool operator(size_t pos) const; // for b[i]; reference operator(size_t pos); // for b[i]; unsigned long to_ulong() const; template <class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> to_string() const;
And add a description of the new member function to 220.127.116.11 [bitset.members],
below the description of the existing
possible), with the following text:
unsigned long long to_ullong() const;
overflow_errorif the integral value
xcorresponding to the bits in
*thiscannot be represented as type
unsigned long long.