Boost logo

Boost :

Subject: Re: [boost] [utility/swap] MSVC 10 test failure, unsigned long to std::bitset conversion invalid?
From: Niels Dekker - address until 2010-10-10 (niels_address_until_2010-10-10_at_[hidden])
Date: 2010-03-09 06:07:06


>> You see, the test code said:
>>
>> typedef std::bitset<8> bitset_type;
>> const bitset_type initial_value1 = 1ul;
>> const bitset_type initial_value2 = 2ul;
>>
>> And C++0x no longer offers a bitset(unsigned long)
>> constructor, according to the Working Draft at
>> http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2010/n3035.pdf

Robert Stewart wrote:
> I can see that being an issue if the tests are compiled with C++0x
> features enabled. Otherwise, MSVC 10 is wrong.

I'm not sure, but it looks like MSVC 10 will always have its C++0x features
enabled. The <bitset> header of MSVC 10 beta 1 only offers the old C++98/03
bitset(unsigned long) constructor if the macro _HAS_CPP0X is /not/ defined.
But apparently _HAS_CPP0X /is/ defined, at least on the msvc-10.0 RC
configuration tested here by Juergen Hunold, and on the regression site,
www.boost.org/development/tests/trunk/RWVC10.html I tried to un-define
_HAS_CPP0X (compiler option "/u _HAS_CPP0X"), but it doesn't seem to work.

> I understand that MSVC introduced an int overload for some reason.

Note that Christopher Jefferson has just submitted an issue to the Library
Working Group, which might support MSVC's extension:
http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#1325

This LWG issue says:
> 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);

However, I'm not convinced that this issue is properly solved by just adding
a bitset(int) constructor (as MSVC 10 RC does).

We wrote:
>> Otherwise, if there is really no platform-independent way to
>> initialize a std::bitset by means of an integer type of
>> argument, I think I'd rather go for string literals:
>>
>> typedef std::bitset<8> bitset_type;
>> const bitset_type initial_value1("01");
>> const bitset_type initial_value2("10");
>
> That would be silly, but it would work. How about default
> constructing and then setting the bits you want?

That would certainly be an option as well. Although in general I'd rather
directly initialize an object to the desired value, of course. Especially
because it allows me to declare the object "const".

Thanks,

  Niels

--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center 

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk