It's common wisdom that you can't return a reference to an array. I've read Why doesn't C++ support functions returning arrays? and one of the answers goes into long winded speculation that it's a design decision. Another answer suggests using a vector or struct instead (what??) and also says:
The array you return would degrade to a pointer though, so you would not be able to work out its size just from its return.
But it's also common wisdom that you can preserve the size of an array by using a reference. The following works for example:
int arr[10];
int (&func())[10]
{
return arr;
}
int main()
{
int (&arr)[10] = func();
for (int i = 0; i < 10; ++i)
std::cout << i << " ";
}
Aside from the usual "you should use a vector or std::array" what's wrong with this approach? I'm unable to see why people care so much about returning an array when this is possible.