Boost logo

Boost :

Subject: Re: [boost] [utility/swap] MSVC 10 test failure, unsigned long to std::bitset conversion invalid?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-03-08 11:56:00

Niels Dekker wrote:
> Robert Stewart wrote:
> > I agree that your test isn't about initialization, but I'd have
> > thought the better thing would be to conditionally compile MSVC 10
> > initialization logic to avoid breaking any other working platform.
> Thanks Robert. But I'm not /entirely/ sure if the compile
> errors in the the
> test code are a true *bug* in the MSVC 10 release candidate.
> 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

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

> I think I understand your point of view. But personally I'd
> rather have all
> platforms compiling the same code, instead of having
> platform-specific #ifdef's. Of course there are situations
> when platform-specific #ifdef's
> are necessary, but I'd rather avoid them.

I can certainly appreciate that.

> Anyway, do you think the lines of code I committed yesterday
> are at least *supposed* to work on all platforms?
> typedef std::bitset<8> bitset_type;
> const bitset_type initial_value1 = 1;
> const bitset_type initial_value2 = 2;

For C++0x, the ints will be promoted to unsigned long long. For C++98/03, they will be promoted to unsigned long. Therefore, using int is appropriate for implementations that exactly match the standards.

I understand that MSVC introduced an int overload for some reason. Assuming that overload behaves as expected, then it will be an exact match and should also provide the desired result.

> 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?

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at