Created on 2007-06-22.00:00:00 last changed 171 months ago
Proposed resolution:
For simplicity, instead of adding overloads for unsigned long
long
and dealing with possible ambiguities in the spec, replace
the bitset
ctor that takes an unsigned long
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 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 [bitset.cons], p2:
bitset(unsigned long long val);
Effects: Constructs an object of class bitset<N>, initializing the first
M
bit positions to the corresponding bit values inval
.M
is the smaller ofN
and the number of bits in the value representation (section [basic.types]) ofunsigned long long
. IfM < N
istrue
, the remaining bit positions are initialized to zero.
Additionally, introduce a new member function to_ullong()
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 to_ulong()
in [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; unsigned long long to_ullong() 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 [bitset.members],
below the description of the existing to_ulong()
(if
possible), with the following text:
unsigned long long to_ullong() const;
Throws:
overflow_error
if the integral valuex
corresponding to the bits in*this
cannot be represented as typeunsigned long long
.Returns:
x
.
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
of 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.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg3459 |
2007-06-22 00:00:00 | admin | create |