I am trying to force an out-of-bounds error and cannot. Can some one please tell me why this is occurring. For the first array-for each combination there is no exception thrown when array items exceed those in std::array. The second produces an error when the initialization list is range-exceeded. Thx in advance.
#include<iostream>
#include<array>
int main()
{
std::array<int, 20>test_array; //std:: load iteration, then use for - each
for (int i = 0; i < 22; ++i) //NO initialization list -- no error
{test_array[i] = 2 * i;}
//readback
for(auto & element : test_array)
std::cout<<element;
std::cout<<"||";
//typically
std::array<int,5>my_array {1,2,3,4,5}; //goes out of range of intialization list, throws error
for(auto & elem : my_array)
std::cout<<elem;
return 0;
}