Re: map of valarray
woessner@gmail.com wrote:
I just tried to create a map<int, valarray<int> > and got some really
weird behavior. Here's a simple example:
int main()
{
std::map<int, std::valarray<int> > m;
std::valarray<int> v(3);
v[0] = 13;
v[1] = 42;
v[2] = 99;
m[0] = v;
std::cout << m[0][0] << ", " << m[0][1] << ", " << m[0][2] << '\n';
return EXIT_SUCCESS;
}
Instead of getting "13, 42, 99", I got "0, 0, 0". And, sure enough, if
I change valarray to vector, I get the expected output.
This is my first time using valarrays. Is there some hidden pitfall
I'm missing? Or is this possible an implementation problem? (For
reference, I'm using g++ 4.1.0).
After adding the necessary #includes for <iostream>, <map>, and
<valarray>, I get the output:
13, 42, 99
using VC++ 7.1 (VS .NET 2003). However, using g++ 3.4.4-2 I get the
same "0, 0, 0" output, so I would guess that it's a g++ implementation
issue.
--
Marcus Kwok
Replace 'invalid' with 'net' to reply