Created on 1998-11-06.00:00:00 last changed 171 months ago
Rationale:
Although the problem is real, the standard is designed that way so it is not a defect. Education is the immediate workaround. A future standard may wish to consider the Proposed Resolution as an extension.
Proposed resolution:
Add to [template.bitset] a bitset constructor declaration
explicit bitset(const char*);
and in Section [bitset.cons] add:
explicit bitset(const char* str);Effects:
Calls bitset((string) str, 0, string::npos);
Duplicate: 778
The following code does not compile with the EDG compiler:
#include <bitset> using namespace std; bitset<32> b("111111111");
If you cast the ctor argument to a string, i.e.:
bitset<32> b(string("111111111"));
then it will compile. The reason is that bitset has the following templatized constructor:
template <class charT, class traits, class Allocator> explicit bitset (const basic_string<charT, traits, Allocator>& str, ...);
According to the compiler vendor, Steve Adamcyk at EDG, the user cannot pass this template constructor a const char* and expect a conversion to basic_string. The reason is "When you have a template constructor, it can get used in contexts where type deduction can be done. Type deduction basically comes up with exact matches, not ones involving conversions."
I don't think the intention when this constructor became templatized was for construction from a const char* to no longer work.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg962 |
2010-10-21 18:28:33 | admin | set | messages: + msg961 |
1998-11-06 00:00:00 | admin | create |