vector<bool> and swap

vector<bool> and swap

Hi,

I am trying to compile the following piece of code using the
intel C++ compiler 7.x on a Mandrake Linux 9.1 system.

---
#include
#include
#include

int main(void)
{
bool a = 1;
bool b = 0;
std::vector va(1,a);
std::vector vb(1,b);

std::swap(va[0],vb[0]);
std::cout << va[0] << " " << vb[0] << std::endl;

}
---

With g++ 3.2.2 this compiles without problems but icpc gives the
following error:

---
test.cpp(12): error: no instance of overloaded function "std::swap" matches the argument list
argument types are: (std::vector>::reference, std::vector>::reference)
std::swap(va[0],vb[0]);
---

If I change `bool' to `int' or `char' it does compile correctly. Is there some special compiler option needed for `bool' to work properly ?

Thanks in advance,

Jeroen

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi, Jeroen:
This is a known issue that caused by the standards.
As always when using "vector", please use the specialized methods defined by "vector". This issue only exists in the "vector".

The best workaround for you is to use "vector"'s swap() function:
std::vector::swap(va[0],vb[0]);

Thanks,
Jennifer

Leave a Comment

Please sign in to add a comment. Not a member? Join today