I was under the impression that std::tr1::array was the same as the boost::array in that it would throw an exception when accessing an index out of bounds. In fact, I took a peek in the header and it appears that way as well. Could someone explain why the following code results in a bus error (gcc version 4.0.1 (Apple Inc. build 5465)) and a segfault on gcc 4.1.2?
Thanks.
#include <exception>
#include <iostream>
#include <string>
#include <tr1/array>
#include <boost/array.hpp>
int main()
{
// boost::array<std::string, 3> arr;
std::tr1::array<std::string, 3> arr;
try
{
arr.at( 0 ) = "one";
arr.at( 1 ) = "two";
arr.at( 2 ) = "three";
arr.at( 3 ) = "nogood";
}
catch ( const std::exception& e )
{
std::cout << "exception: " << e.what() << std::endl;
}
return 0;
}