In C++, the only way to return an array is by reference:
int ( &unity( int (&arr)[3] ) )[3] {
arr[0] = 1; arr[1] = arr[2] = 0;
return arr;
}
Now with C++11, we do have std::array
in the STL. It is now possible to return a std::array
by copy:
#include <array>
std::array< int, 3 > make_unity() {
std::array< int, 3 > arr;
arr[0] = 1; arr[1] = arr[2] = 0;
return arr;
}
Why is that we are forced to use STL when the compiler could have equivalent functionalities ? Why was it impossible to have a return by copy for arrays in C++11 ?